[Lazarus] SynEdit

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] SynEdit

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

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] SynEdit

Martin Frb
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.


>
> 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

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] SynEdit

patspiper
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.

>
>
>>
>> 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
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] SynEdit

Martin Frb
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.

>>
>>
>>>
>>> 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
> [hidden email]
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] SynEdit

patspiper
On 04/04/2011 06:47 PM, Martin wrote:

> 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

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] SynEdit

Martin Frb
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






--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] SynEdit

Martin Frb
On 04/04/2011 19:59, Martin wrote:

> 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

> 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
> [hidden email]
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus