pyscripter / SynEdit

SynEdit is a syntax highlighting edit control, not based on the Windows common controls.
26 stars 11 forks source link

CharIndexToRowCol returns first pos of last line if Index > charcount. #62

Closed MShark67 closed 1 year ago

MShark67 commented 1 year ago

I noticed this when setting SelLength to a value more than the character count of the editor and noticing that it will select up the first character of the last line. To fix it I just added the following check:

    x := Length(Lines[y]);     <-- existing line
    if (y = Lines.Count - 1) and (Index >= Chars + x) then
      break;

Thanks! -Mark

pyscripter commented 1 year ago

Used the slightly more efficient:

    if Chars + x + 2 > Index then
    begin
      x := Index - Chars;
      Break;
    end
    else if (y = Lines.Count - 1) and (Index >= Chars + x) then
      Break;

Please confirm it works.