TodoListLaz: Optimize SynEdit markup for comments / fixes for custom words in comments

This commit is contained in:
Martin 2025-03-24 13:30:13 +01:00
parent 8e59857521
commit 63d93a19f0

View File

@ -16,7 +16,7 @@ uses
LazEditMiscProcs, LazEditMiscProcs,
// SynEdit // SynEdit
SynEditMarkup, SynHighlighterPas, SynEditMiscProcs, SynEdit, SynEditMiscClasses, SynEditTypes, SynEditMarkup, SynHighlighterPas, SynEditMiscProcs, SynEdit, SynEditMiscClasses, SynEditTypes,
SynEditHighlighter; SynEditHighlighter, SynEditHighlighterFoldBase;
type type
@ -189,23 +189,30 @@ var
function GetStartOfComment(var ALineNum: integer; out ALogX: integer): boolean; inline; function GetStartOfComment(var ALineNum: integer; out ALogX: integer): boolean; inline;
var var
lvl: Integer;
IsComment, IsNewCommentStart: Boolean; IsComment, IsNewCommentStart: Boolean;
begin begin
ALogX := 1; ALogX := 1;
FPasHl.StartAtLineIndex(ToIdx(ALineNum)); FPasHl.StartAtLineIndex(ToIdx(ALineNum));
Result := FPasHl.GetTokenIsComment; Result := FPasHl.GetTokenIsComment and (ALineNum > 1);
if (not Result) or if (not Result) or
(FPasHl.GetTokenIsCommentStart(True)) (FPasHl.GetTokenIsCommentStart(True))
then then
exit; exit;
while ALineNum > 1 do begin repeat
dec(ALineNum);
lvl := FPasHl.FoldBlockEndLevel(ToIdx(ALineNum), FOLDGROUP_PASCAL, [sfbIncludeDisabled]);
while (ALineNum > 1) and
(FPasHl.FoldBlockMinLevel(ToIdx(ALineNum), FOLDGROUP_PASCAL, [sfbIncludeDisabled]) >= lvl)
do begin
dec(ALineNum); dec(ALineNum);
if ALineNum = FSkipEndLine then if ALineNum = FSkipEndLine then
exit(False); exit(False);
end;
// Get ALogX and check for nested comment
FPasHl.StartAtLineIndex(ToIdx(ALineNum)); FPasHl.StartAtLineIndex(ToIdx(ALineNum));
IsComment := FPasHl.GetTokenIsComment; IsComment := FPasHl.GetTokenIsComment;
// if not a comment, then pretend its a new start => used for "result" // if not a comment, then pretend its a new start => used for "result"
IsNewCommentStart := (not IsComment) or FPasHl.GetTokenIsCommentStart(True); IsNewCommentStart := (not IsComment) or FPasHl.GetTokenIsCommentStart(True);
@ -224,7 +231,8 @@ var
if Result then if Result then
exit; exit;
end;
until false;
Result := False; Result := False;
end; end;
@ -281,6 +289,11 @@ begin
FFoundPos[0] := FFoundPos[i]; FFoundPos[0] := FFoundPos[i];
SetLength(FFoundPos, 1); SetLength(FFoundPos, 1);
TkEnd := 1 + FPasHl.GetTokenLen; TkEnd := 1 + FPasHl.GetTokenLen;
while (not FPasHl.GetEol) and (not FPasHl.GetTokenIsCommentEnd) do begin
FPasHl.Next;
if not FPasHl.GetTokenIsComment then break;
TkEnd := ToPos(FPasHl.GetTokenPos) + FPasHl.GetTokenLen;
end;
FFoundPos[0].EndPos.Y := aRow; FFoundPos[0].EndPos.Y := aRow;
FFoundPos[0].EndPos.X := TkEnd; FFoundPos[0].EndPos.X := TkEnd;
LogX := TkEnd; LogX := TkEnd;