mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-13 20:39:26 +02:00
SynEdit: fixed crash / undefined behaviour due to invalid caching of highlighter node-info. Issue #0027748
git-svn-id: trunk@48532 -
This commit is contained in:
parent
3459fff08c
commit
901196535a
@ -350,7 +350,8 @@ type
|
|||||||
procedure BeforeDetachedFromRangeList(ARangeList: TSynHighlighterRangeList); virtual;
|
procedure BeforeDetachedFromRangeList(ARangeList: TSynHighlighterRangeList); virtual;
|
||||||
function UpdateRangeInfoAtLine(Index: Integer): Boolean; virtual; // Returns true if range changed
|
function UpdateRangeInfoAtLine(Index: Integer): Boolean; virtual; // Returns true if range changed
|
||||||
// code fold - only valid if hcCodeFolding in Capabilities
|
// code fold - only valid if hcCodeFolding in Capabilities
|
||||||
procedure SetCurrentLines(const AValue: TSynEditStringsBase); virtual;
|
procedure SetCurrentLines(const AValue: TSynEditStringsBase); virtual; // todo remove virtual
|
||||||
|
procedure DoCurrentLinesChanged; virtual;
|
||||||
property LineIndex: Integer read FLineIndex;
|
property LineIndex: Integer read FLineIndex;
|
||||||
property CurrentRanges: TSynHighlighterRangeList read FCurrentRanges;
|
property CurrentRanges: TSynHighlighterRangeList read FCurrentRanges;
|
||||||
function GetDrawDivider(Index: integer): TSynDividerDrawConfigSetting; virtual;
|
function GetDrawDivider(Index: integer): TSynDividerDrawConfigSetting; virtual;
|
||||||
@ -1733,6 +1734,12 @@ begin
|
|||||||
if FCurrentLines <> nil
|
if FCurrentLines <> nil
|
||||||
then FCurrentRanges := TSynHighlighterRangeList(AValue.Ranges[GetRangeIdentifier])
|
then FCurrentRanges := TSynHighlighterRangeList(AValue.Ranges[GetRangeIdentifier])
|
||||||
else FCurrentRanges := nil;
|
else FCurrentRanges := nil;
|
||||||
|
DoCurrentLinesChanged;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSynCustomHighlighter.DoCurrentLinesChanged;
|
||||||
|
begin
|
||||||
|
//
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSynCustomHighlighter.AttachToLines(Lines: TSynEditStringsBase);
|
procedure TSynCustomHighlighter.AttachToLines(Lines: TSynEditStringsBase);
|
||||||
|
@ -165,8 +165,8 @@ type
|
|||||||
procedure ClearData;
|
procedure ClearData;
|
||||||
procedure ClearFilteredList;
|
procedure ClearFilteredList;
|
||||||
procedure DoFilter(MinIndex: Integer = -1);
|
procedure DoFilter(MinIndex: Integer = -1);
|
||||||
procedure SetLine(ALine: TLineIdx);
|
procedure SetLine(ALine: TLineIdx); // Does not clear anything, if line has not changed.
|
||||||
procedure SetLineClean(ALine: TLineIdx);
|
procedure SetLineClean(ALine: TLineIdx); // Does not clear anything, if line has not changed.
|
||||||
property HighLighter: TSynCustomFoldHighlighter read FHighLighter write FHighLighter;
|
property HighLighter: TSynCustomFoldHighlighter read FHighLighter write FHighLighter;
|
||||||
public
|
public
|
||||||
// used by HighLighters to add data
|
// used by HighLighters to add data
|
||||||
@ -301,6 +301,7 @@ type
|
|||||||
fRanges: TSynCustomHighlighterRanges;
|
fRanges: TSynCustomHighlighterRanges;
|
||||||
FRootCodeFoldBlock: TSynCustomCodeFoldBlock;
|
FRootCodeFoldBlock: TSynCustomCodeFoldBlock;
|
||||||
FFoldNodeInfoList: TLazSynFoldNodeInfoList;
|
FFoldNodeInfoList: TLazSynFoldNodeInfoList;
|
||||||
|
procedure ClearFoldNodeList;
|
||||||
protected
|
protected
|
||||||
// "Range"
|
// "Range"
|
||||||
function GetRangeClass: TSynCustomHighlighterRangeClass; virtual;
|
function GetRangeClass: TSynCustomHighlighterRangeClass; virtual;
|
||||||
@ -379,6 +380,9 @@ type
|
|||||||
procedure SetLine(const NewValue: String;
|
procedure SetLine(const NewValue: String;
|
||||||
LineNumber:Integer // 0 based
|
LineNumber:Integer // 0 based
|
||||||
); override;
|
); override;
|
||||||
|
procedure DoCurrentLinesChanged; override;
|
||||||
|
function PerformScan(StartIndex, EndIndex: Integer; ForceEndIndex: Boolean =
|
||||||
|
False): Integer; override;
|
||||||
public
|
public
|
||||||
property FoldConfig[Index: Integer]: TSynCustomFoldConfig
|
property FoldConfig[Index: Integer]: TSynCustomFoldConfig
|
||||||
read GetFoldConfig write SetFoldConfig;
|
read GetFoldConfig write SetFoldConfig;
|
||||||
@ -920,6 +924,19 @@ begin
|
|||||||
FCodeFoldRange.MinimumCodeFoldBlockLevel := FCodeFoldRange.FCodeFoldStackSize;
|
FCodeFoldRange.MinimumCodeFoldBlockLevel := FCodeFoldRange.FCodeFoldStackSize;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TSynCustomFoldHighlighter.DoCurrentLinesChanged;
|
||||||
|
begin
|
||||||
|
inherited DoCurrentLinesChanged;
|
||||||
|
ClearFoldNodeList;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TSynCustomFoldHighlighter.PerformScan(StartIndex, EndIndex: Integer;
|
||||||
|
ForceEndIndex: Boolean): Integer;
|
||||||
|
begin
|
||||||
|
ClearFoldNodeList;
|
||||||
|
Result := inherited PerformScan(StartIndex, EndIndex, ForceEndIndex);
|
||||||
|
end;
|
||||||
|
|
||||||
function TSynCustomFoldHighlighter.CurrentCodeFoldBlockLevel: integer;
|
function TSynCustomFoldHighlighter.CurrentCodeFoldBlockLevel: integer;
|
||||||
begin
|
begin
|
||||||
assert(FCodeFoldRange <> nil, 'MinimumCodeFoldBlockLevel requires FCodeFoldRange');
|
assert(FCodeFoldRange <> nil, 'MinimumCodeFoldBlockLevel requires FCodeFoldRange');
|
||||||
@ -1028,6 +1045,16 @@ begin
|
|||||||
DefHighlightChange(self);
|
DefHighlightChange(self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TSynCustomFoldHighlighter.ClearFoldNodeList;
|
||||||
|
begin
|
||||||
|
if FFoldNodeInfoList <> nil then begin
|
||||||
|
if (FFoldNodeInfoList.RefCount > 1) then
|
||||||
|
ReleaseRefAndNil(FFoldNodeInfoList)
|
||||||
|
else
|
||||||
|
FFoldNodeInfoList.Clear;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TSynCustomFoldHighlighter.GetFoldNodeInfo(Line: TLineIdx
|
function TSynCustomFoldHighlighter.GetFoldNodeInfo(Line: TLineIdx
|
||||||
): TLazSynFoldNodeInfoList;
|
): TLazSynFoldNodeInfoList;
|
||||||
begin
|
begin
|
||||||
@ -1038,7 +1065,11 @@ begin
|
|||||||
FFoldNodeInfoList := CreateFoldNodeInfoList;
|
FFoldNodeInfoList := CreateFoldNodeInfoList;
|
||||||
FFoldNodeInfoList.AddReference;
|
FFoldNodeInfoList.AddReference;
|
||||||
FFoldNodeInfoList.HighLighter := Self;
|
FFoldNodeInfoList.HighLighter := Self;
|
||||||
end;
|
end
|
||||||
|
else
|
||||||
|
if (CurrentRanges <> nil) and (CurrentRanges.NeedsReScanStartIndex >= 0) then
|
||||||
|
ClearFoldNodeList;
|
||||||
|
|
||||||
|
|
||||||
Result := FFoldNodeInfoList;
|
Result := FFoldNodeInfoList;
|
||||||
Result.SetLineClean(Line);
|
Result.SetLineClean(Line);
|
||||||
|
Loading…
Reference in New Issue
Block a user