SynEdit: FoldedView, fix accessing out of range lines (due to wrong internal fTopViewPos). Introduced in 86abcd75d9

This commit is contained in:
Martin 2025-03-09 12:44:46 +01:00
parent 482124d17e
commit 847f6ab0e4

View File

@ -3429,8 +3429,15 @@ begin
CurFoldedBefore := node.FoldedBefore;
ViewIdx := ToIdx(fTopViewPos + CurFoldedBefore);
TxtIdx := NextLines.DisplayView.ViewToTextIndexEx(ViewIdx, ViewRange);
cnt := NextLines.Count;
// Prepare data for line one above fTopViewPos
if (TxtIdx >= cnt) or (TxtIdx < -1) then begin
// Past end of Text
NewCapability := [];
NewClassifications := [];
end
else begin
If ViewIdx > ViewRange.Top then begin
// Need CurLine.... data for wrapped lines
CurLineCapability := FFoldProvider.LineCapabilities[TxtIdx];
@ -3464,6 +3471,7 @@ begin
NewCapability := NewCapability + [cfFoldBody];
NewCapability := NewCapability - [cfFoldStart, cfHideStart];
end;
end;
// Add entry for line one above virtual topViewPos
if (fFoldTypeList[0].Capability <> NewCapability) or
@ -3478,7 +3486,6 @@ begin
{$IFDEF SynFoldDebug}debugln(['FOLD-- CalculateMaps fTopViewPos:=', fTopViewPos, ' TxtIdx=',TxtIdx]);{$ENDIF}
cnt := NextLines.Count;
for i := 1 to fLinesInWindow + 2 do begin
if (TxtIdx >= cnt) or (TxtIdx < -1) then begin
// Past end of Text