« Return to Thread: Avoiding Moving The Cursor Before Start of Document

Re: Avoiding Moving The Cursor Before Start of Document

by Hal Vaughan-2 :: Rate this Message:

Reply to Author | View in Thread


On Jun 27, 2009, at 3:51 AM, Cor Nouws wrote:

> Hi Hal,
>
> Thnks for posting back.
> Your proposed solution looks OK. When you have the final version,  
> I'll try to take a closer look. Maybe you can post it as extension  
> on the extension site?

I still have to find the site and look up how to post it.  I was  
looking over what I had done and thought I had published this for  
others, but, perhaps with that one bug, I hadn't done that.  I also  
like to do a write-up and put anything like that on my blog when I do  
it.

The code is below.  It's working now.  I also noticed a LONG delay  
from when I submit my emails to this list and when they show up.  I'll  
have to see if I've changed my email address since I joined or  
something like that.

I left in the comment where the bug was.  It's not there now.  Of  
course, since I've gotten it working, I get a good point from someone  
else where I could have just checked the result of goLeft().  I may re-
write it, but that breaks a person coding rule of mine: If it ain't  
broke, don't fix it.  (I've spend WAY too much of my life in front of  
a CRT writing code!)


Hal

>
> Regards - Cor
>
> Hal Vaughan wrote (26-6-2009 17:19)
>> I may have a solution that's a bit different than what's been  
>> suggested, but thanks to both Cor and Fernand because what they  
>> wrote gave me the idea.  I still have to code this and be sure it's  
>> what I want.  A quick check tells me that if I have one character  
>> at the beginning, once I move the cursor over that character, I can  
>> keep trying oCurse.goLeft(), but the length of the string in the  
>> selection (sKey in this case) does not change.  So I think I can  
>> just keep track of the length of the selected string.  If I try  
>> goLeft() and the string length doesn't change, that should tell me  
>> I can't go left anymore and I'm at the beginning.
>> If this works, I'll post a fixed version.  I think I also exported  
>> this or was going to so other people could use them as well.  If I  
>> haven't done it already, I will.  I like it because it's a lot like  
>> AutoCorrect, but I can define new key phrases and replacement texts  
>> in a hurry and they are stored in the document, but can be exported  
>> to a text file and imported in another document, so they are  
>> document specific but can be transferred.

Sub InsertAutoMacroText
        oDoc = ThisComponent
        oCurs = oDoc.getCurrentController().getViewCursor()
        iEnd = false
        iCount = 0
        Do
                oCurs.goLeft(1, true)
                sKey = oCurs.getString()
                If iCount = Len(sKey) Then
                        iEnd = true
                        iCount = 0
                Else
                        sChar = Left(sKey, 1)
' MsgBox "String: " + sKey + ", Char: " + sChar
'BUG: This next line throws an error if we try to use this at the  
start of a
'document.
                        iChar = Asc(sChar)
' MsgBox "String: " + sKey + ", Char: " + sChar + ", Char Code: " +  
iChar
                        iCount = Len(sKey)
                        If iChar < 33 Then iEnd = true
                        If iCount > 32 Then iEnd = true
                End If
        Loop Until iEnd
        If iCount > 0 Then oCurs.goRight(1, true)
        sKey = oCurs.getString()
' sText = "Replaced ->" + sKey + "<-"
        sText = GetDocumentVariable(sKey)
        oCurs.setString(sText)
        oCurs.collapseToEnd()
End Sub

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...

 « Return to Thread: Avoiding Moving The Cursor Before Start of Document