Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-04

SynEdit

7 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

patspiper

Hi,

1- How can TSynCompletion's ItemList be filled depending on what is before the dot(.)? I know the Lazarus IDE does it, but I couldn't figure it out.

TEdit.|

If Ctrl+Space is pressed, then the list of TEdit properties should popup. Currentstring is empty. How can we read the word before the dot?

2- Any reason why TSynCompletion is not a palette component, and has to be created through code?

Thanks,
Stephano

Reply by email

Martin
to patspiper
patspiper wrote 10 lines
Hi, 1- How can TSynCompletion's ItemList be filled depending on what is before the dot(.)? I know the Lazarus IDE does it, but I couldn't figure it out. TEdit.| If Ctrl+Space is pressed, then the list of TEdit properties should popup. Currentstring is empty. How can we read the word before the dot?

There is an example on how to use it, in the example folder.

It should show you which callbacks are triggered, so you can place code of your own there.

2- Any reason why TSynCompletion is not a palette component, and has to be created through code?

Yes and no.

It needs some real refactor, and deprecating a method/property will allow people to change there code easily (if enough time is given before the final remove) => but as soon as stuff get's into the lfm, it gets way harder.
Though I have no idea, when, if ever, I get to that.

Martin

Reply by email

patspiper
to Martin
Martin wrote 16 lines
On 04/04/2011 16:20, patspiper wrote: > Hi, > > 1- How can TSynCompletion's ItemList be filled depending on what is > before the dot(.)? I know the Lazarus IDE does it, but I couldn't > figure it out. > > TEdit.| > > If Ctrl+Space is pressed, then the list of TEdit properties should > popup. Currentstring is empty. How can we read the word before the dot? There is an example on how to use it, in the example folder. It should show you which callbacks are triggered, so you can place code of your own there.

I checked the 3 examples before posting. They show how to use CurrentString (which is after the dot), but not how to read the token before the dot.

Show quoted text 13 lines
> > 2- Any reason why TSynCompletion is not a palette component, and has > to be created through code? Yes and no. It needs some real refactor, and deprecating a method/property will allow people to change there code easily (if enough time is given before the final remove) => but as soon as stuff get's into the lfm, it gets way harder. Though I have no idea, when, if ever, I get to that.

You've done a already great job on Synedit!

Thanks,
Stephano

Reply by email

Martin
to patspiper
patspiper wrote 20 lines
On 04/04/2011 06:30 PM, Martin wrote: > On 04/04/2011 16:20, patspiper wrote: >> Hi, >> >> 1- How can TSynCompletion's ItemList be filled depending on what is >> before the dot(.)? I know the Lazarus IDE does it, but I couldn't >> figure it out. >> >> TEdit.| >> >> If Ctrl+Space is pressed, then the list of TEdit properties should >> popup. Currentstring is empty. How can we read the word before the dot? > > There is an example on how to use it, in the example folder. > > It should show you which callbacks are triggered, so you can place > code of your own there. I checked the 3 examples before posting. They show how to use CurrentString (which is after the dot), but not how to read the token before the dot.

ok, I may be able to look into it later.

but what about using LogicalCaretXY, then getting the line, and reading it?

possible subtracting the length of CurrentString.

Show quoted text 23 lines
> > >> >> 2- Any reason why TSynCompletion is not a palette component, and has >> to be created through code? > > Yes and no. > > It needs some real refactor, and deprecating a method/property will > allow people to change there code easily (if enough time is given > before the final remove) => but as soon as stuff get's into the lfm, > it gets way harder. > Though I have no idea, when, if ever, I get to that. You've done a already great job on Synedit! Thanks, Stephano -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

patspiper
to Martin
Martin wrote 29 lines
On 04/04/2011 16:44, patspiper wrote: > On 04/04/2011 06:30 PM, Martin wrote: >> On 04/04/2011 16:20, patspiper wrote: >>> Hi, >>> >>> 1- How can TSynCompletion's ItemList be filled depending on what is >>> before the dot(.)? I know the Lazarus IDE does it, but I couldn't >>> figure it out. >>> >>> TEdit.| >>> >>> If Ctrl+Space is pressed, then the list of TEdit properties should >>> popup. Currentstring is empty. How can we read the word before the >>> dot? >> >> There is an example on how to use it, in the example folder. >> >> It should show you which callbacks are triggered, so you can place >> code of your own there. > I checked the 3 examples before posting. They show how to use > CurrentString (which is after the dot), but not how to read the token > before the dot. ok, I may be able to look into it later. 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.

Thanks,
Stephano

Reply by email

Martin
to patspiper
patspiper wrote 19 lines
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

Reply by email

Martin
to Martin
Martin wrote 48 lines
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)
x:= LC.x-length(CurrentString)  -1

somehow the -1 got lost

Show quoted text 25 lines
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 -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email