[Lazarus] SynEdit

Martin lazarus at mfriebe.de
Mon Apr 4 20:59:47 CEST 2011


On 04/04/2011 17:23, patspiper wrote:
> On 04/04/2011 06:47 PM, Martin wrote:
>>
>> but what about using LogicalCaretXY, then getting the line, and 
>> reading it?
>>
>> possible subtracting the length of CurrentString.
> I am almost there (by giving it another shot at the ide sources):
>
>   Line:=SynEdit1.LineText;
>   p1:=SynEdit1.LogicalCaretXY;
>   if (p1.x>length(Line)+1) or (Line='') then exit;
>   SynEdit1.GetWordBoundsAtRowCol(p1, x1, x2);
>   // There must be a saner way than subtracting 2
>   p1.x := x1-2;
>   SynEdit1.GetWordBoundsAtRowCol(p1, x1, x2);
>   WordToken := copy(Line, x1, x2);
>
> However, what is the correct way to go back to the previous token? 
> Subtracting 2 is not the way.

The caret is at the end of currentstring.
So your dot should be 1 before. But if you allow spaces after the dot, 
then it can be anything before..., and maybe you even allow it on the 
previous line?

Note that LogicalCaret is 1 based, and 1 is before the first char.
Also you must use LogicalCaret, normal Caret will not work if there are 
multybyte chars, or tabs.
- LogicalCaret: BYTE (not char) pos in text
-Caret (sometime PhysicalCaret): screenpos, a tab is one byte in the 
text, but may be 4 chars on the screen // an a-umlaut is 2 bytes in the 
text, but 1 on the screen)

If your line is
ABC.def
And the caret is between the A and B, then  LogicalCaret.X = 2 (1 would 
be before the A)

So if you are behind the "def" LC.x = 8
x := LC.x - len(CurrentString);

makes x = 8 - 3 = 5
LineString[5] = 'd'

so you need to subtract another one to see the char before currentstring
x:= LC.x-length(CurrentString)

while (x> 1) and (linestring[x] in[#32,#9]) do dec(x);

Now you should be on the first none space, before the currentstring....

and so on,
It all depends on what you believe a word/token is, what are the 
boundaries...

You can look at GetWordBoundsAtRowCol....

maybe it expects to be NOT at the end of the word, so by substracting 
one more (-2) you get into the middle (or to the start) of the word???

Not sure, haven't looked at









More information about the Lazarus mailing list