mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-15 10:19:23 +02:00
SynEdit: IFDEF lowlight, fix wrong index, and fix using same nested comment setting as HL / Issue #0025244
git-svn-id: trunk@43332 -
This commit is contained in:
parent
5532f47222
commit
6b7452699a
@ -25,7 +25,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
SysUtils, Classes, SynEditMiscClasses, SynHighlighterPas, SynEditMarkupHighAll,
|
SysUtils, Classes, SynEditMiscClasses, SynHighlighterPas, SynEditMarkupHighAll,
|
||||||
SynEditHighlighterFoldBase, SynEditFoldedView, LazSynEditText, SynEditMiscProcs,
|
SynEditHighlighterFoldBase, SynEditFoldedView, LazSynEditText, SynEditMiscProcs,
|
||||||
SynEditMarkup, SynEditPointClasses, LazClasses, LazLoggerBase, Graphics,
|
SynEditMarkup, SynEditPointClasses, SynEditHighlighter, LazClasses, LazLoggerBase, Graphics,
|
||||||
LCLProc;
|
LCLProc;
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -319,6 +319,13 @@ type
|
|||||||
procedure SetLines(AValue: TSynEditStrings);
|
procedure SetLines(AValue: TSynEditStrings);
|
||||||
function GetHighLighterWithLines: TSynCustomFoldHighlighter;
|
function GetHighLighterWithLines: TSynCustomFoldHighlighter;
|
||||||
private
|
private
|
||||||
|
//copied from SynEdit
|
||||||
|
//TODO, move to highlighter
|
||||||
|
function GetHighlighterAttriAtRowColEx(XY: TPoint; out Token: string;
|
||||||
|
out TokenType, Start: Integer;
|
||||||
|
out Attri: TSynHighlighterAttributes): boolean; //L505
|
||||||
|
|
||||||
|
|
||||||
procedure MaybeRequestNodeStates(var ANode: TSynMarkupHighIfDefLinesNodeInfo);
|
procedure MaybeRequestNodeStates(var ANode: TSynMarkupHighIfDefLinesNodeInfo);
|
||||||
procedure MaybeValidateNode(var ANode: TSynMarkupHighIfDefLinesNodeInfo);
|
procedure MaybeValidateNode(var ANode: TSynMarkupHighIfDefLinesNodeInfo);
|
||||||
procedure MaybeExtendNodeBackward(var ANode: TSynMarkupHighIfDefLinesNodeInfo;
|
procedure MaybeExtendNodeBackward(var ANode: TSynMarkupHighIfDefLinesNodeInfo;
|
||||||
@ -1828,7 +1835,8 @@ begin
|
|||||||
if Result.LastEntryEndLine > ALinePos then begin
|
if Result.LastEntryEndLine > ALinePos then begin
|
||||||
Result.LastEntryEndLineOffs := 0;
|
Result.LastEntryEndLineOffs := 0;
|
||||||
Assert(Result.EntryCount > 0, 'Result.EntryCount > 0 : in Outer Nesting');
|
Assert(Result.EntryCount > 0, 'Result.EntryCount > 0 : in Outer Nesting');
|
||||||
Result.Entry[Result.EntryCount].MakeUnknown;
|
Result.Entry[Result.EntryCount-1].MakeUnknown;
|
||||||
|
//Result.Entry[Result.EntryCount].MakeUnknown;
|
||||||
//Result.; xxxxxxxxxxxxxxxxxxxxxxxx TODO invalidate
|
//Result.; xxxxxxxxxxxxxxxxxxxxxxxx TODO invalidate
|
||||||
end;
|
end;
|
||||||
Result := FindNodeAtPosition(ALinePos, afmCreate);
|
Result := FindNodeAtPosition(ALinePos, afmCreate);
|
||||||
@ -2334,6 +2342,39 @@ begin
|
|||||||
Result.CurrentLines := FLines;
|
Result.CurrentLines := FLines;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TSynMarkupHighIfDefLinesTree.GetHighlighterAttriAtRowColEx(XY: TPoint; out
|
||||||
|
Token: string; out TokenType, Start: Integer; out Attri: TSynHighlighterAttributes): boolean;
|
||||||
|
var
|
||||||
|
PosX, PosY: integer;
|
||||||
|
Line: string;
|
||||||
|
begin
|
||||||
|
PosY := XY.Y -1;
|
||||||
|
if Assigned(Highlighter) and (PosY >= 0) and (PosY < FLines.Count) then
|
||||||
|
begin
|
||||||
|
Line := FLines[PosY];
|
||||||
|
fHighlighter.CurrentLines := FLines;
|
||||||
|
Highlighter.StartAtLineIndex(PosY);
|
||||||
|
PosX := XY.X;
|
||||||
|
if (PosX > 0) and (PosX <= Length(Line)) then begin
|
||||||
|
while not Highlighter.GetEol do begin
|
||||||
|
Start := Highlighter.GetTokenPos + 1;
|
||||||
|
Token := Highlighter.GetToken;
|
||||||
|
if (PosX >= Start) and (PosX < Start + Length(Token)) then begin
|
||||||
|
Attri := Highlighter.GetTokenAttribute;
|
||||||
|
TokenType := Highlighter.GetTokenKind;
|
||||||
|
Result := TRUE;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
Highlighter.Next;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
Token := '';
|
||||||
|
Attri := nil;
|
||||||
|
TokenType := -1;
|
||||||
|
Result := FALSE;
|
||||||
|
end;
|
||||||
|
|
||||||
function TSynMarkupHighIfDefLinesTree.CreateNode(APosition: Integer): TSynSizedDifferentialAVLNode;
|
function TSynMarkupHighIfDefLinesTree.CreateNode(APosition: Integer): TSynSizedDifferentialAVLNode;
|
||||||
begin
|
begin
|
||||||
IncChangeStep;
|
IncChangeStep;
|
||||||
@ -2433,54 +2474,53 @@ var
|
|||||||
FoldNodeInfoList: TLazSynFoldNodeInfoList;
|
FoldNodeInfoList: TLazSynFoldNodeInfoList;
|
||||||
LineTextLower: String;
|
LineTextLower: String;
|
||||||
LineLen, NodesAddedCnt: Integer;
|
LineLen, NodesAddedCnt: Integer;
|
||||||
LineNeedsReq, LineChanged, HasUncommentedNodes, NestComments: Boolean;
|
LineNeedsReq, LineChanged, HasUncommentedNodes: Boolean;
|
||||||
|
|
||||||
function FindCloseCurlyBracket(StartX: Integer; out ALineOffs: Integer): Integer;
|
function FindCloseCurlyBracket(StartX: Integer; out ALineOffs: Integer;
|
||||||
|
ASearchComment: Boolean = False; AMaxLine: Integer = -1): Integer;
|
||||||
var
|
var
|
||||||
CurlyLvl: Integer;
|
len, i, c, tk, x: Integer;
|
||||||
i, l, c: Integer;
|
dummy: String;
|
||||||
s: String;
|
attr: TSynHighlighterAttributes;
|
||||||
|
r: TSynCustomHighlighterRange;
|
||||||
|
f: TRangeStates;
|
||||||
begin
|
begin
|
||||||
Result := StartX;
|
Result := StartX;
|
||||||
ALineOffs := 0;
|
ALineOffs := 0;
|
||||||
CurlyLvl := 1;
|
|
||||||
|
|
||||||
l := Length(LineTextLower);
|
|
||||||
while Result <= l do begin
|
|
||||||
case LineTextLower[Result] of
|
|
||||||
'{': if NestComments then inc(CurlyLvl);
|
|
||||||
'}': if CurlyLvl = 1 then exit
|
|
||||||
else dec(CurlyLvl);
|
|
||||||
end;
|
|
||||||
inc(Result);
|
|
||||||
end;
|
|
||||||
|
|
||||||
c := Lines.Count;
|
c := Lines.Count;
|
||||||
i := ToIdx(ALine) + 1;
|
i := ALine;
|
||||||
inc(ALineOffs);
|
|
||||||
while (i < c) do begin
|
while (i <= c) do begin
|
||||||
// TODO: get range flag fron pas highlighter
|
len := Length(Lines[ToIdx(i)]);
|
||||||
s := Lines[i];
|
if len > 0 then begin
|
||||||
l := Length(s);
|
GetHighlighterAttriAtRowColEx(Point(StartX, i), dummy, tk, x, attr);
|
||||||
Result := 1;
|
Result := x + Length(dummy) - 1;
|
||||||
while Result <= l do begin
|
if Result < len - 1 then
|
||||||
case s[Result] of
|
exit;
|
||||||
'{': if NestComments then inc(CurlyLvl);
|
r := TSynCustomHighlighterRange(Highlighter.GetRange);
|
||||||
'}': if CurlyLvl = 1 then exit
|
f := TRangeStates(Integer(PtrUInt(r.RangeType)));
|
||||||
else dec(CurlyLvl);
|
if ASearchComment then begin
|
||||||
end;
|
if (f * [rsAnsi, rsBor] = []) or ( (AMaxLine > 0) and (i > AMaxLine) ) then
|
||||||
inc(Result);
|
exit;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if not (rsDirective in f) then
|
||||||
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
inc(i);
|
inc(i);
|
||||||
inc(ALineOffs);
|
inc(ALineOffs);
|
||||||
|
StartX := 1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Result := -1;
|
Result := -1;
|
||||||
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function IsCommentedIfDef(AEntry: TSynMarkupHighIfDefEntry): Boolean;
|
function IsCommentedIfDef(AEntry: TSynMarkupHighIfDefEntry): Boolean;
|
||||||
var
|
var
|
||||||
i, j, o: Integer;
|
i, j, k, FoundOffs, LastLineOffs: Integer;
|
||||||
s: String;
|
s: String;
|
||||||
begin
|
begin
|
||||||
i := AEntry.StartColumn;
|
i := AEntry.StartColumn;
|
||||||
@ -2495,19 +2535,27 @@ var
|
|||||||
exit;
|
exit;
|
||||||
|
|
||||||
j := AEntry.EndColumn;
|
j := AEntry.EndColumn;
|
||||||
|
LastLineOffs := AEntry.Line.LastEntryEndLineOffs;
|
||||||
if (idnMultiLineTag in AEntry.NodeFlags) then
|
if (idnMultiLineTag in AEntry.NodeFlags) then
|
||||||
s := Lines[ToIdx(ALine+AEntry.Line.LastEntryEndLineOffs)]
|
s := Lines[ToIdx(ALine + LastLineOffs)]
|
||||||
else
|
else
|
||||||
s := LineTextLower;
|
s := LineTextLower;
|
||||||
Result :=
|
Result :=
|
||||||
(j-1 <= length(s)) and (j > 1) and (s[j-1] = '}') and
|
(j-1 <= length(s)) and (j > 1) and (s[j-1] = '}') and
|
||||||
(TheDict.GetMatchAtChar(@LineTextLower[i], LineLen + 1 - i) in [1, 4]) and
|
(TheDict.GetMatchAtChar(@LineTextLower[i], LineLen + 1 - i) in [1, 4]);
|
||||||
(j = FindCloseCurlyBracket(i+1, o)+1);
|
// Old closing is inside the comment?
|
||||||
|
|
||||||
|
if Result then begin
|
||||||
|
k := FindCloseCurlyBracket(i+1, FoundOffs, True, ALine+LastLineOffs)+1;
|
||||||
|
Result := (LastLineOffs < FoundOffs) or
|
||||||
|
( (LastLineOffs = FoundOffs) and (j < k) );
|
||||||
|
|
||||||
|
//if Result then // FoundOffs is evaluated
|
||||||
|
// Result :=
|
||||||
|
// ((not (idnMultiLineTag in AEntry.NodeFlags)) and (FoundOffs = 0)) or
|
||||||
|
// ((idnMultiLineTag in AEntry.NodeFlags) and (o = AEntry.Line.LastEntryEndLineOffs));
|
||||||
|
end;
|
||||||
|
|
||||||
if Result then // o is evaluated
|
|
||||||
Result :=
|
|
||||||
((not (idnMultiLineTag in AEntry.NodeFlags)) and (o = 0)) or
|
|
||||||
((idnMultiLineTag in AEntry.NodeFlags) and (o = AEntry.Line.LastEntryEndLineOffs));
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function GetEntry(ALogStart, ALogEnd, ALineOffs: Integer;
|
function GetEntry(ALogStart, ALogEnd, ALineOffs: Integer;
|
||||||
@ -2608,7 +2656,7 @@ var
|
|||||||
//RelNestDepth, RelNestDepthNext: Integer;
|
//RelNestDepth, RelNestDepthNext: Integer;
|
||||||
NType: TSynMarkupIfdefNodeType;
|
NType: TSynMarkupIfdefNodeType;
|
||||||
begin
|
begin
|
||||||
NestComments := Highlighter.NestedComments;
|
//NestComments := Highlighter.NestedComments;
|
||||||
LineNeedsReq := False;
|
LineNeedsReq := False;
|
||||||
LineChanged := False;
|
LineChanged := False;
|
||||||
HasUncommentedNodes := False;
|
HasUncommentedNodes := False;
|
||||||
|
Loading…
Reference in New Issue
Block a user