Recent

Author Topic: Synedit question  (Read 4232 times)

snorkel

  • Hero Member
  • *****
  • Posts: 817
Synedit question
« on: March 16, 2013, 04:15:15 am »
Hi,
I need to get the previous token from the current caret position, is there a way to do this?

I found a NextToken function but no previous one.

Thanks
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Synedit question
« Reply #1 on: March 16, 2013, 04:34:52 am »
from the sources:
Code: [Select]
    function NextTokenPos: TPoint; virtual; deprecated; // use next word pos instead
    function NextWordPos: TPoint; virtual;
    function PrevWordPos: TPoint; virtual;

You shouldn't use NextTokenPos as it is deprecated.

But if you need to stick to highlighter tokens, instead of words, then there is no such function.

What do you need it for?

snorkel

  • Hero Member
  • *****
  • Posts: 817
Re: Synedit question
« Reply #2 on: March 18, 2013, 05:44:25 pm »
Hi Martin,
What I want to do is when the user types something like this:

select * from te <---then hits ctrl space I want to detect if the last word is from,update or into and then fill the completion list with the table names from the sqlite database.

I have it kind of working by testing if the current completion text <> '' then subtracting the length of the current completion text - caretX so I can call getprevword and check if it's one of the keywords for tables.  If I don't move the caret back a bit getprevword grabs whatever the user entered prior to hitting ctrl+space.

Thanks :-)
***Snorkel***
If I forget, I always use the latest stable 32bit version of Lazarus and FPC. At the time of this signature that is Laz 3.0RC2 and FPC 3.2.2
OS: Windows 10 64 bit

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Synedit question
« Reply #3 on: March 18, 2013, 07:15:28 pm »
Yes, for that you should use the word functions. You also have

    procedure GetWordBoundsAtRowCol(const XY: TPoint; out StartX, EndX: integer);
    function GetWordAtRowCol(XY: TPoint): string;

 

TinyPortal © 2005-2018