SynEdit: Debug TSynPluginSyncroEdit.Scan and remove an assertion. Issue #41446.

This commit is contained in:
Juha 2025-02-20 18:12:55 +02:00
parent 7d5c7fba25
commit 41f4be3c95
2 changed files with 30 additions and 28 deletions

View File

@ -2214,7 +2214,7 @@ var
begin
len := Length(aLine);
if (aX < 1) or (aX > len + 1) then exit(False);
Result := ((ax <= len) and (aLine[aX] in FWordChars)) or
Result := ((aX <= len) and (aLine[aX] in FWordChars)) or
((aX > 1) and (aLine[aX - 1] in FWordChars));
end;
@ -2234,7 +2234,7 @@ var
begin
len := Length(aLine);
if (aX <= 1) or (aX > len + 1) or (len = 0) then exit(False);
Result := ((ax = len + 1) or not(aLine[aX] in FWordChars)) and
Result := ((aX = len + 1) or not(aLine[aX] in FWordChars)) and
(aLine[aX - 1] in FWordChars);
end;
@ -2249,8 +2249,8 @@ begin
inc(aX);
if (aX > len + 1) then exit(-1);
if (aX > 1) and (aLine[aX - 1] in FWordChars) then
while (aX <= len) and (aLine[aX] in FWordChars) do Inc(ax);
while (aX <= len) and not(aLine[aX] in FWordChars) do Inc(ax);
while (aX <= len) and (aLine[aX] in FWordChars) do Inc(aX);
while (aX <= len) and not(aLine[aX] in FWordChars) do Inc(aX);
if aX > len then
exit(-1);
Result := aX;
@ -2267,10 +2267,10 @@ begin
inc(aX);
if (aX > len + 1) then exit(-1);
if (aX = 1) or not(aLine[aX - 1] in FWordChars) then begin
while (aX <= len) and not(aLine[aX] in FWordChars) do Inc(ax);
while (aX <= len) and not(aLine[aX] in FWordChars) do Inc(aX);
if (aX >= len + 1) then exit(-1);
end;
while (aX <= len) and (aLine[aX] in FWordChars) do Inc(ax);
while (aX <= len) and (aLine[aX] in FWordChars) do Inc(aX);
Result := aX;
end;
@ -2283,10 +2283,10 @@ begin
if (aX < 1) or (aX > len + 1) then exit(-1);
if not aIncludeCurrent then
dec(aX);
while (aX >= 1) and ( (ax > len) or not(aLine[aX] in FWordChars) ) do Dec(ax);
while (aX >= 1) and ( (aX > len) or not(aLine[aX] in FWordChars) ) do Dec(aX);
if aX = 0 then
exit(-1);
while (aX >= 1) and ( (ax > len) or (aLine[aX] in FWordChars) ) do Dec(ax);
while (aX >= 1) and ( (aX > len) or (aLine[aX] in FWordChars) ) do Dec(aX);
Result := aX + 1;
end;
@ -2300,8 +2300,8 @@ begin
if not aIncludeCurrent then
dec(aX);
if aX <= len then
while (aX >= 1) and (aLine[aX] in FWordChars) do Dec(ax);
while (aX >= 1) and ( (ax > len) or not(aLine[aX] in FWordChars) ) do Dec(ax);
while (aX >= 1) and (aLine[aX] in FWordChars) do Dec(aX);
while (aX >= 1) and ( (aX > len) or not(aLine[aX] in FWordChars) ) do Dec(aX);
if aX = 0 then
exit(-1);
Result := aX + 1;
@ -2314,18 +2314,18 @@ var
begin
len := Length(aLine);
if (aX < 1) then exit(-1);
if aIncludeCurrent then dec(ax);
if (ax > len) then exit(-1);
if aIncludeCurrent then dec(aX);
if (aX > len) then exit(-1);
if (aX > 0) and (aLine[aX] in FWordChars) then
while (aX <= len) and (aLine[aX] in FWordChars) do Inc(ax)
while (aX <= len) and (aLine[aX] in FWordChars) do Inc(aX)
else
if (aX > 0) and (aLine[aX] in FWordBreakChars) then
while (aX <= len) and (aLine[aX] in FWordBreakChars) do Inc(ax)
while (aX <= len) and (aLine[aX] in FWordBreakChars) do Inc(aX)
else
begin
while (aX <= len) and ((aX = 0) or (aLine[aX] in FWhiteChars)) do Inc(ax);
if (ax > len) then exit(-1);
while (aX <= len) and ((aX = 0) or (aLine[aX] in FWhiteChars)) do Inc(aX);
if (aX > len) then exit(-1);
end;
Result := aX;
end;
@ -2337,17 +2337,17 @@ var
begin
len := Length(aLine);
if (aX > len + 1) then exit(-1);
if not aIncludeCurrent then dec(ax);
if not aIncludeCurrent then dec(aX);
if (aX < 1) then exit(-1);
if (aX <= len) and (aLine[aX] in FWordChars) then
while (aX >= 1) and (aLine[aX] in FWordChars) do dec(ax)
while (aX >= 1) and (aLine[aX] in FWordChars) do dec(aX)
else
if (aX <= len) and (aLine[aX] in FWordBreakChars) then
while (aX >= 1) and (aLine[aX] in FWordBreakChars) do dec(ax)
while (aX >= 1) and (aLine[aX] in FWordBreakChars) do dec(aX)
else
begin
while (aX >= 1) and ((aX > len) or (aLine[aX] in FWhiteChars)) do dec(ax);
while (aX >= 1) and ((aX > len) or (aLine[aX] in FWhiteChars)) do dec(aX);
if aX = 0 then exit(-1);
end;
Result := aX + 1;

View File

@ -29,7 +29,7 @@ uses
Classes, Controls, SysUtils, Forms, Graphics, SynEditMiscClasses, LCLType,
SynEdit, SynPluginSyncronizedEditBase, LazSynEditText, SynEditMiscProcs,
SynEditMouseCmds, SynEditKeyCmds, SynEditTypes, SynEditHighlighter, LCLIntf,
LazUTF8;
LazUTF8, LazLoggerBase;
type
@ -393,7 +393,7 @@ begin
i := alen;
pWord := PChar(aWord);
while i > 0 do begin
v := ord(pWord^);
v := ord(pWord^);
a := a + v * (1 + (n mod 8));
if a > 550 then a := a mod 550;
b := b * 3 + v * n - p;
@ -844,8 +844,10 @@ var
if (we^.Count = 2) and (we^.LineIdx >= 0) then begin
if FScanModes * [spssWithCase, spssCtxWithCase] <> [] then begin
Wrd := Copy(ViewedTextBuffer[we^.LineIdx], we^.BytePos, ALen);
assert(UTF8LowerCase(Wrd) = LWrd, 'AddWordToHash: UTF8LowerCase(Wrd) = LWrd');
//Wrd := Copy(ViewedTextBuffer[we^.LineIdx], we^.BytePos, ALen);
DebugLn(['TSynPluginSyncroEdit.Scan: Wrd=', Wrd,
', UTF8LowerCase(Wrd)=', UTF8LowerCase(Wrd), ', LWrd=', LWrd]);
//Assert(UTF8LowerCase(Wrd) = LWrd, 'AddWordToHash: UTF8LowerCase(Wrd) <> LWrd');
if spssWithCase in FScanModes then
FWordIndex[spssWithCase].AddWord(ToIdx(AFrom.y), AStart, Wrd);
@ -870,14 +872,14 @@ begin
if BackWard then begin
Line := ViewedTextBuffer[ToIdx(AFrom.y)];
while (AFrom >= aTo) do begin
AFrom.x := WordBreaker.PrevWordEnd(Line, AFrom.x, True);
AFrom.x := WordBreaker.PrevWordEnd(Line, AFrom.x, True);
if AFrom.x < 0 then begin
dec(AFrom.y);
Line := ViewedTextBuffer[ToIdx(AFrom.y)];
AFrom.x := length(Line) + 1;
continue;
end;
x2 := WordBreaker.PrevWordStart(Line, AFrom.x, True);
x2 := WordBreaker.PrevWordStart(Line, AFrom.x, True);
if (AFrom.y > ATo.y) or (x2 >= ATo.x) then begin
AddWordToHash(x2, AFrom.x - x2);
Result := AFrom;
@ -891,14 +893,14 @@ begin
else begin
Line := ViewedTextBuffer[ToIdx(AFrom.y)];
while (AFrom <= aTo) do begin
AFrom.x := WordBreaker.NextWordStart(Line, AFrom.x, True);
AFrom.x := WordBreaker.NextWordStart(Line, AFrom.x, True);
if AFrom.x < 0 then begin
inc(AFrom.y);
AFrom.x := 1;
Line := ViewedTextBuffer[ToIdx(AFrom.y)];
continue;
end;
x2 := WordBreaker.NextWordEnd(Line, AFrom.x, True);
x2 := WordBreaker.NextWordEnd(Line, AFrom.x, True);
if (AFrom.y < ATo.y) or (x2 <= ATo.x) then begin
AddWordToHash(AFrom.x, x2 - AFrom.x);
Result := AFrom;