mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 23:19:28 +02:00
SynEdit: FoldView, rename/refactor TextToViewIndex/ViewToTextIndex to be 0-based
git-svn-id: trunk@63175 -
This commit is contained in:
parent
0f8b9dd9a8
commit
cbb6115663
@ -1902,7 +1902,7 @@ begin
|
||||
if not Assigned(FTextArea) then
|
||||
Result := -1
|
||||
else
|
||||
Result := FFoldedLinesView.ViewPosToTextIndex(FTextArea.TopLine) + 1;
|
||||
Result := FFoldedLinesView.ViewToTextIndex(ToIdx(FTextArea.TopLine)) + 1;
|
||||
end;
|
||||
|
||||
procedure TCustomSynEdit.SetBlockTabIndent(AValue: integer);
|
||||
@ -4740,7 +4740,7 @@ begin
|
||||
|
||||
if not HandleAllocated then
|
||||
Include(fStateFlags, sfExplicitTopLine);
|
||||
NewTopView := FFoldedLinesView.TextIndexToViewPos(Value-1);
|
||||
NewTopView := ToPos(FFoldedLinesView.TextToViewIndex(ToIdx(Value)));
|
||||
if NewTopView <> TopView then begin
|
||||
TopView := NewTopView;
|
||||
end;
|
||||
@ -6822,22 +6822,22 @@ begin
|
||||
end;
|
||||
ecEditorTop, ecSelEditorTop:
|
||||
begin
|
||||
FCaret.LineCharPos := Point(1, FFoldedLinesView.ViewPosToTextIndex(1)+1);
|
||||
FCaret.LineCharPos := Point(1, ToPos(FFoldedLinesView.ViewToTextIndex(0)));
|
||||
end;
|
||||
ecEditorBottom, ecSelEditorBottom:
|
||||
begin
|
||||
CaretNew := Point(1, FFoldedLinesView.ViewPosToTextIndex(FFoldedLinesView.Count)+1);
|
||||
CaretNew := Point(1, ToPos(FFoldedLinesView.ViewToTextIndex(ToIdx(FFoldedLinesView.Count))));
|
||||
if (CaretNew.Y > 0) then
|
||||
CaretNew.X := Length(FTheLinesView[CaretNew.Y - 1]) + 1;
|
||||
FCaret.LineCharPos := CaretNew;
|
||||
end;
|
||||
ecColSelEditorTop:
|
||||
begin
|
||||
FCaret.LinePos := FFoldedLinesView.ViewPosToTextIndex(1)+1;
|
||||
FCaret.LinePos := ToPos(FFoldedLinesView.ViewToTextIndex(0));
|
||||
end;
|
||||
ecColSelEditorBottom:
|
||||
begin
|
||||
FCaret.LinePos := FFoldedLinesView.ViewPosToTextIndex(FFoldedLinesView.Count)+1;
|
||||
FCaret.LinePos := ToPos(FFoldedLinesView.ViewToTextIndex(ToIdx(FFoldedLinesView.Count)));
|
||||
end;
|
||||
|
||||
// goto special line / column position
|
||||
@ -8388,7 +8388,7 @@ begin
|
||||
if not(eoScrollPastEol in fOptions) then begin
|
||||
// move to begin of next line
|
||||
NewCaret.Y:= FFoldedLinesView.TextPosAddLines(FCaret.LinePos, +1);
|
||||
if NewCaret.Y <= FFoldedLinesView.ViewPosToTextIndex(FFoldedLinesView.Count)+1 then begin
|
||||
if NewCaret.Y <= ToPos(FFoldedLinesView.ViewToTextIndex(ToIdx(FFoldedLinesView.Count))) then begin
|
||||
NewCaret.X := 1;
|
||||
FCaret.LineBytePos := NewCaret;
|
||||
end;
|
||||
|
@ -438,9 +438,9 @@ type
|
||||
destructor Destroy; override;
|
||||
|
||||
// Converting between Folded and Unfolded Lines/Indexes
|
||||
function TextIndexToViewPos(aTextIndex : Integer) : Integer; (* Convert TextIndex (0-based) to ViewPos (1-based) *)
|
||||
function TextToViewIndex(aTextIndex : TLineIdx) : TLineIdx; (* Convert TextIndex (0-based) to ViewPos (1-based) *)
|
||||
function TextIndexToScreenLine(aTextIndex : Integer) : Integer; (* Convert TextIndex (0-based) to Screen (0-based) *)
|
||||
function ViewPosToTextIndex(aViewPos : Integer) : Integer; (* Convert ViewPos (1-based) to TextIndex (0-based) *)
|
||||
function ViewToTextIndex(aViewIndex : TLineIdx) : TLineIdx; (* Convert ViewPos (1-based) to TextIndex (0-based) *)
|
||||
function ScreenLineToTextIndex(aLine : Integer) : Integer; (* Convert Screen (0-based) to TextIndex (0-based) *)
|
||||
|
||||
function TextIndexAddLines(aTextIndex, LineOffset : Integer) : Integer; (* Add/Sub to/from TextIndex (0-based) skipping folded *)
|
||||
@ -738,7 +738,7 @@ begin
|
||||
FFoldView.MarkupInfoHiddenCodeLine.SetFrameBoundsLog(1, MaxInt, 0);
|
||||
end;
|
||||
|
||||
inherited SetHighlighterTokensLine(FFoldView.ViewPosToTextIndex(ALine + 1), ARealLine);
|
||||
inherited SetHighlighterTokensLine(FFoldView.ViewToTextIndex(ALine), ARealLine);
|
||||
end;
|
||||
|
||||
function TLazSynDisplayFold.GetNextHighlighterToken(out ATokenInfo: TLazSynDisplayTokenInfo): Boolean;
|
||||
@ -839,18 +839,18 @@ function TLazSynDisplayFold.TextToViewIndex(AIndex: TLineIdx): TLineRange;
|
||||
begin
|
||||
Result := inherited TextToViewIndex(AIndex);
|
||||
if Result.Top = Result.Bottom then begin
|
||||
Result.Top := FFoldView.TextIndexToViewPos(Result.Top) - 1;
|
||||
Result.Top := FFoldView.TextToViewIndex(Result.Top);
|
||||
Result.Bottom := Result.Top;
|
||||
end
|
||||
else begin;
|
||||
Result.Top := FFoldView.TextIndexToViewPos(Result.Top) - 1;
|
||||
Result.Bottom := FFoldView.TextIndexToViewPos(Result.Bottom) - 1;
|
||||
Result.Top := FFoldView.TextToViewIndex(Result.Top);
|
||||
Result.Bottom := FFoldView.TextToViewIndex(Result.Bottom);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TLazSynDisplayFold.ViewToTextIndex(AIndex: TLineIdx): TLineIdx;
|
||||
begin
|
||||
Result := FFoldView.ViewPosToTextIndex(inherited ViewToTextIndex(AIndex)+1);
|
||||
Result := FFoldView.ViewToTextIndex(inherited ViewToTextIndex(AIndex));
|
||||
end;
|
||||
|
||||
{ TSynEditFoldExportStream }
|
||||
@ -3148,7 +3148,7 @@ end;
|
||||
|
||||
//procedure TSynEditFoldedView.LinesInsertedAtViewPos(AStartPos, ALineCount : Integer; SkipFixFolding : Boolean);
|
||||
//begin
|
||||
// LinesInsertedAtTextIndex(ViewPosToTextIndex(AStartPos), ALineCount, SkipFixFolding);
|
||||
// LinesInsertedAtTextIndex(ViewToTextIndex(ToIdx(AStartPos)), ALineCount, SkipFixFolding);
|
||||
//end;
|
||||
|
||||
procedure TSynEditFoldedView.LinesDeletedAtTextIndex(AStartIndex, ALineCount, ABytePos: Integer; SkipFixFolding : Boolean);
|
||||
@ -3165,33 +3165,33 @@ end;
|
||||
|
||||
//procedure TSynEditFoldedView.LinesDeletedAtViewPos(AStartPos, ALineCount : Integer; SkipFixFolding : Boolean);
|
||||
//begin
|
||||
// LinesDeletedAtTextIndex(ViewPosToTextIndex(AStartPos), ALineCount, SkipFixFolding);
|
||||
// LinesDeletedAtTextIndex(ViewToTextIndex(ToIdx(AStartPos)), ALineCount, SkipFixFolding);
|
||||
//end;
|
||||
|
||||
function TSynEditFoldedView.TextIndexToViewPos(aTextIndex : Integer) : Integer;
|
||||
function TSynEditFoldedView.TextToViewIndex(aTextIndex: TLineIdx): TLineIdx;
|
||||
var
|
||||
n: TSynTextFoldAVLNode;
|
||||
begin
|
||||
n := fFoldTree.FindFoldForLine(aTextIndex + 1);
|
||||
if n.IsInFold then
|
||||
Result := n.StartLine - 1 - n.FoldedBefore
|
||||
Result := ToIdx(n.StartLine) - 1 - n.FoldedBefore
|
||||
else
|
||||
Result := aTextIndex + 1 - n.FoldedBefore;
|
||||
Result := aTextIndex - n.FoldedBefore;
|
||||
end;
|
||||
|
||||
function TSynEditFoldedView.TextIndexToScreenLine(aTextIndex : Integer) : Integer;
|
||||
begin
|
||||
Result := TextIndexToViewPos(aTextIndex) - TopLine;
|
||||
Result := TextToViewIndex(aTextIndex) - TopLine + 1;
|
||||
end;
|
||||
|
||||
function TSynEditFoldedView.ViewPosToTextIndex(aViewPos : Integer) : Integer;
|
||||
function TSynEditFoldedView.ViewToTextIndex(aViewIndex: TLineIdx): TLineIdx;
|
||||
begin
|
||||
result := aViewPos - 1 + fFoldTree.FindFoldForFoldedLine(aViewPos).FoldedBefore;
|
||||
result := aViewIndex + fFoldTree.FindFoldForFoldedLine(ToPos(aViewIndex)).FoldedBefore;
|
||||
end;
|
||||
|
||||
function TSynEditFoldedView.ScreenLineToTextIndex(aLine : Integer) : Integer;
|
||||
begin
|
||||
Result := ViewPosToTextIndex(aLine + TopLine);
|
||||
Result := ViewToTextIndex(aLine + TopLine - 1);
|
||||
end;
|
||||
|
||||
function TSynEditFoldedView.TextIndexAddLines(aTextIndex, LineOffset : Integer) : Integer;
|
||||
@ -3202,7 +3202,7 @@ begin
|
||||
node := fFoldTree.FindFoldForLine(aTextIndex+1, True);
|
||||
result := aTextIndex;
|
||||
if LineOffset < 0 then begin
|
||||
boundary := Max(0, ViewPosToTextIndex(1));
|
||||
boundary := Max(0, ViewToTextIndex(0));
|
||||
if node.IsInFold
|
||||
then node := node.Prev
|
||||
else node := fFoldTree.FindLastFold;
|
||||
|
@ -158,7 +158,7 @@ begin
|
||||
tmp2 := FoldView.FoldType[AScreenLine-1];
|
||||
FIsFoldHidePreviousLine := False;
|
||||
|
||||
if (AScreenLine = 0) and (FoldView.TextIndexToViewPos(FoldView.TextIndex[0]) = 1) and
|
||||
if (AScreenLine = 0) and (FoldView.TextToViewIndex(FoldView.TextIndex[0]) = 0) and
|
||||
(cfCollapsedHide in tmp2)
|
||||
then begin
|
||||
Result := cfCollapsedHide;
|
||||
|
@ -14,7 +14,7 @@ uses
|
||||
Classes, SysUtils, math, testregistry, TestBase, TestHighlightPas, Forms,
|
||||
LCLProc, SynEdit, SynHighlighterPas, SynEditFoldedView,
|
||||
SynEditHighlighterFoldBase, SynGutterCodeFolding, SynEditKeyCmds,
|
||||
SynEditTypes;
|
||||
SynEditTypes, SynEditMiscProcs;
|
||||
|
||||
type
|
||||
|
||||
@ -163,10 +163,10 @@ begin
|
||||
i := 0;
|
||||
while i < high(AExpectedPairs)-1 do begin
|
||||
AssertEquals(AName+' TxtIdx('+IntToStr( AExpectedPairs[i])+') to ViewPos[1-based]('+IntToStr( AExpectedPairs[i+1])+') ',
|
||||
AExpectedPairs[i+1], FoldedView.TextIndexToViewPos(AExpectedPairs[i]));
|
||||
AExpectedPairs[i+1], ToPos(FoldedView.TextToViewIndex(AExpectedPairs[i])));
|
||||
if ADoReverse then
|
||||
AssertEquals(AName+' ViewPos[1-based]('+IntToStr( AExpectedPairs[i+1])+') to TxtIdx('+IntToStr( AExpectedPairs[i])+') [R]',
|
||||
AExpectedPairs[i], FoldedView.ViewPosToTextIndex(AExpectedPairs[i+1]));
|
||||
AExpectedPairs[i], FoldedView.ViewToTextIndex(ToIdx(AExpectedPairs[i+1])));
|
||||
inc(i, 2);
|
||||
end;
|
||||
end;
|
||||
@ -178,10 +178,10 @@ begin
|
||||
i := 0;
|
||||
while i < high(AExpectedPairs)-1 do begin
|
||||
AssertEquals(AName+' ViewPos[1-based]('+IntToStr( AExpectedPairs[i])+') to TxtIdx('+IntToStr( AExpectedPairs[i+1])+')',
|
||||
AExpectedPairs[i+1], FoldedView.ViewPosToTextIndex(AExpectedPairs[i]));
|
||||
AExpectedPairs[i+1], FoldedView.ViewToTextIndex(ToIdx(AExpectedPairs[i])));
|
||||
if ADoReverse then
|
||||
AssertEquals(AName+' TxtIdx('+IntToStr( AExpectedPairs[i+1])+') to ViewPos[1-based]('+IntToStr( AExpectedPairs[i])+') [R]',
|
||||
AExpectedPairs[i], FoldedView.TextIndexToViewPos(AExpectedPairs[i+1]));
|
||||
AExpectedPairs[i], ToPos(FoldedView.TextToViewIndex(AExpectedPairs[i+1])));
|
||||
inc(i, 2);
|
||||
end;
|
||||
end;
|
||||
|
@ -1819,7 +1819,7 @@ end;
|
||||
|
||||
function TIDESynEditor.TextIndexToViewPos(aTextIndex: Integer): Integer;
|
||||
begin
|
||||
Result := TextView.TextIndexToViewPos(aTextIndex - 1);
|
||||
Result := ToPos(TextView.TextToViewIndex(ToIdx(aTextIndex)));
|
||||
end;
|
||||
|
||||
{$IFDEF WinIME}
|
||||
@ -2824,8 +2824,8 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
HasFolds := FoldView.TextIndexToViewPos(y2) - FoldView.TextIndexToViewPos(y1) <> y2 - y1;
|
||||
//debugln(['*** HasFolds=', HasFolds, ' y1=',y1, ' y2=',y2, ' VP1=',FoldView.TextIndexToViewPos(y1), ' VP2=',FoldView.TextIndexToViewPos(y2)]);
|
||||
HasFolds := FoldView.TextToViewIndex(y2) - FoldView.TextToViewIndex(y1) <> y2 - y1;
|
||||
//debugln(['*** HasFolds=', HasFolds, ' y1=',y1, ' y2=',y2, ' VP1=',FoldView.TextToViewIndex(y1), ' VP2=',FoldView.TextToViewIndex(y2)]);
|
||||
|
||||
FProv := FoldView.FoldProvider;
|
||||
Tree := TIDESynEditor(SynEdit).FMarkupIfDef.IfDefTree;
|
||||
|
Loading…
Reference in New Issue
Block a user