Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synedit - Word at cursor - proposal #51

Closed
JaFi-cz opened this issue May 6, 2021 · 1 comment
Closed

Synedit - Word at cursor - proposal #51

JaFi-cz opened this issue May 6, 2021 · 1 comment
Labels

Comments

@JaFi-cz
Copy link
Contributor

JaFi-cz commented May 6, 2021

Word at cursor should return word even cursor is just behind the word. Current behavior:
|word - true
wo|rd - true
word| - false

I suggest to make modification of this behavior
Unit Synedit.PAS

function TCustomSynEdit.GetWordAtRowCol(XY: TBufferCoord): string;
var
  Line: string;
  Len, Start, Stop: Integer;
begin
  Result := '';
  if (XY.Line >= 1) and (XY.Line <= Lines.Count) then
  begin
    Line := Lines[XY.Line - 1];
    Len := Length(Line);
    { Len + 1 is for case when word is the last word and cursor is behind it }
    if (Len > 0) and
       ((XY.Char >= 1) and (XY.Char <= Len + 1)) and
       (IsIdentChar(Line[XY.Char]) or IsIdentChar(Line[XY.Char-1])) then        //Fiala
    begin
       if IsIdentChar(Line[XY.Char]) then                                       //Fiala
         Start := XY.Char
       else
         Start := XY.Char - 1;
       while (Start > 1) and IsIdentChar(Line[Start - 1]) do
          Dec(Start);

       Stop := XY.Char;                                                         //Fiala
       while (Stop <= Len + 1) and IsIdentChar(Line[Stop]) do
          Inc(Stop);

       Result := Copy(Line, Start, Stop - Start);
    end;
  end;
end;
@JaFi-cz JaFi-cz changed the title Word at cursor - proposal Synedit - Word at cursor - proposal May 7, 2021
@pyscripter
Copy link
Contributor

I have used the slightly simpler:

function TCustomSynEdit.GetWordAtRowCol(XY: TBufferCoord): string;
var
  Line: string;
  Len, Start, Stop: Integer;
begin
  Result := '';
  if (XY.Line >= 1) and (XY.Line <= Lines.Count) then
  begin
    Line := Lines[XY.Line - 1];
    Len := Length(Line);
    if (Len > 0) and InRange(XY.Char, 1, Len + 1) then
    begin
       Start := XY.Char;
       while (Start > 1) and IsIdentChar(Line[Start - 1]) do
          Dec(Start);

       Stop := XY.Char;
       while (Stop <= Len) and IsIdentChar(Line[Stop]) do
          Inc(Stop);

       Result := Copy(Line, Start, Stop - Start);
    end;
  end;
end;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants