SynEdit: Changed TextPosAddLines (foldview) to AddVisibleOffsetToTextIndex (textview)

git-svn-id: trunk@63209 -
This commit is contained in:
martin 2020-05-22 14:54:22 +00:00
parent 237ac26a28
commit a6cca4acfe
4 changed files with 28 additions and 21 deletions

View File

@ -333,6 +333,8 @@ type
function TextToViewIndex(aTextIndex : TLineIdx) : TLineIdx; virtual;
function ViewToTextIndex(aViewIndex : TLineIdx) : TLineIdx; virtual;
function AddVisibleOffsetToTextIndex(aTextIndex: TLineIdx; LineOffset : Integer) : TLineIdx; virtual; (* Add/Sub to/from TextIndex (0-based) skipping invisible (folded) *)
public
// Currently Lines are physical
procedure EditInsert(LogX, LogY: Integer; AText: String); virtual; abstract;
@ -1213,6 +1215,12 @@ begin
Result := aViewIndex;
end;
function TSynEditStrings.AddVisibleOffsetToTextIndex(aTextIndex: TLineIdx;
LineOffset: Integer): TLineIdx;
begin
Result := aTextIndex + LineOffset;
end;
{ TSynEditStringsLinked }
function TSynEditStringsLinked.Add(const S: string): integer;

View File

@ -2192,7 +2192,6 @@ begin
FBlockSelection.Caret := FCaret;
FBlockSelection.InvalidateLinesMethod := @InvalidateLines;
FBlockSelection.AddChangeHandler(@DoBlockSelectionChanged);
FBlockSelection.{%H-}FoldedView := FFoldedLinesView;
FInternalBlockSelection := TSynEditSelection.Create(FTheLinesView, False);
FInternalBlockSelection.InvalidateLinesMethod := @InvalidateLines;
@ -6541,7 +6540,7 @@ begin
if CaretY < TopLine then
TopLine := CaretY
else if CaretY > ScreenRowToRow(Max(1, LinesInWindow) - 1) then //mh 2000-10-19
TopLine := FFoldedLinesView.TextPosAddLines(CaretY, -Max(0, LinesInWindow-1))
TopLine := ToPos(FTheLinesView.AddVisibleOffsetToTextIndex(ToIdx(CaretY), -Max(0, LinesInWindow-1)))
else
TopView := TopView; //mh 2000-10-19
end;
@ -8340,7 +8339,7 @@ begin
if DX < 0 then begin
if (FCaret.LinePos > 1) and not(eoScrollPastEol in fOptions) then begin
// move to end of prev line
NewCaret.Y:= FFoldedLinesView.TextPosAddLines(FCaret.LinePos, -1);
NewCaret.Y:= ToPos(FTheLinesView.AddVisibleOffsetToTextIndex(ToIdx(FCaret.LinePos), -1));
if NewCaret.Y <> FCaret.LinePos then begin
s:=FTheLinesView[NewCaret.Y-1];
NewCaret.X := length(s) + 1;
@ -8351,7 +8350,7 @@ begin
else begin
if not(eoScrollPastEol in fOptions) then begin
// move to begin of next line
NewCaret.Y:= FFoldedLinesView.TextPosAddLines(FCaret.LinePos, +1);
NewCaret.Y:= ToPos(FTheLinesView.AddVisibleOffsetToTextIndex(ToIdx(FCaret.LinePos), +1));
if NewCaret.Y <= ToPos(FTheLinesView.ViewToTextIndex(ToIdx(FTheLinesView.ViewedCount))) then begin
NewCaret.X := 1;
FCaret.LineBytePos := NewCaret;
@ -8372,7 +8371,7 @@ var
begin
OldCaret:=CaretXY;
NewCaret:=OldCaret;
NewCaret.Y:=FFoldedLinesView.TextPosAddLines(NewCaret.Y, DY);
NewCaret.Y:=ToPos(FTheLinesView.AddVisibleOffsetToTextIndex(ToIdx(NewCaret.Y), DY));
DoIncPaintLock(Self); // No editing is taking place
FCaret.LinePos := NewCaret.Y;
DoDecPaintLock(Self);
@ -8395,10 +8394,10 @@ begin
if MakeSelectionVisible then begin
//l1 := FBlockSelection.FirstLineBytePos;;
LBottomLine := FFoldedLinesView.TextPosAddLines(TopLine, LinesInWindow);
LBottomLine := ToPos(FTheLinesView.AddVisibleOffsetToTextIndex(ToIdx(TopLine), LinesInWindow));
LCaretFirst := CaretY;
LCaretLast := Max(1, FFoldedLinesView.TextPosAddLines(CaretY, 1-LinesInWindow)); // Will have caret on last visible line
LCaretLast := Max(1, ToPos(FTheLinesView.AddVisibleOffsetToTextIndex(ToIdx(CaretY), 1-LinesInWindow))); // Will have caret on last visible line
l1 := Min(LCaretFirst, FBlockSelection.FirstLineBytePos.y);
l2 := Max(LCaretFirst, FBlockSelection.LastLineBytePos.y);
@ -8414,7 +8413,7 @@ begin
// Scrolling down, LastLine = L2
TopLine := Max(LCaretLast,
Min(LCaretFirst,
FFoldedLinesView.TextPosAddLines(L2, 1-LinesInWindow)
ToPos(FTheLinesView.AddVisibleOffsetToTextIndex(ToIdx(L2), 1-LinesInWindow))
));
end
else begin
@ -8428,7 +8427,7 @@ begin
if l2 > LBottomLine then
TopLine := Max(LCaretLast,
Min(LCaretFirst,
FFoldedLinesView.TextPosAddLines(L2, 1-LinesInWindow)
ToPos(FTheLinesView.AddVisibleOffsetToTextIndex(ToIdx(L2), 1-LinesInWindow))
));
end;
end;

View File

@ -407,6 +407,7 @@ type
procedure SetTopTextIndex(const AIndex : integer);
procedure SetLinesInWindow(const AValue : integer);
procedure DoFoldChanged(AnIndex: Integer);
function TextIndexAddLines(aTextIndex, LineOffset : Integer) : Integer; (* Add/Sub to/from TextIndex (0-based) skipping folded *)
protected
procedure SetManager(AManager: TSynTextViewsManager); override;
procedure SetSynStrings(AValue: TSynEditStrings); override;
@ -445,8 +446,7 @@ type
function TextIndexToScreenLine(aTextIndex : Integer) : Integer; (* Convert TextIndex (0-based) to Screen (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 *)
function TextPosAddLines(aTextpos, LineOffset : Integer) : Integer; (* Add/Sub to/from TextPos (1-based) skipping folded *)
function AddVisibleOffsetToTextIndex(aTextIndex: TLineIdx; LineOffset: Integer): TLineIdx; override; (* Add/Sub to/from TextPos (1-based) skipping folded *)
property BlockSelection: TSynEditSelection write SetBlockSelection;
// Attributes for Visible-Lines-On-screen
@ -3228,9 +3228,12 @@ begin
end;
end;
function TSynEditFoldedView.TextPosAddLines(aTextpos, LineOffset : Integer) : Integer;
function TSynEditFoldedView.AddVisibleOffsetToTextIndex(aTextIndex: TLineIdx;
LineOffset: Integer): TLineIdx;
begin
Result := TextIndexAddLines(aTextpos-1, LineOffset)+1;
//TODO: Modify LineOffset then call inherited;
Result := TextIndexAddLines(aTextIndex, LineOffset);
// Result := inherited AddVisibleOffsetToTextIndex(aTextIndex, LineOffset);
end;
procedure TSynEditFoldedView.Lock;

View File

@ -103,7 +103,6 @@ type
TSynEditSelection = class(TSynEditPointBase)
private
FFoldedView: TObject;
FOnBeforeSetSelText: TSynBeforeSetSelTextList;
FAutoExtend: Boolean;
FCaret: TSynEditCaret;
@ -218,8 +217,6 @@ type
property AutoExtend: Boolean read FAutoExtend write SetAutoExtend;
property StickyAutoExtend: Boolean read FStickyAutoExtend write FStickyAutoExtend;
property Hide: Boolean read FHide write SetHide;
property FoldedView: TObject read FFoldedView write FFoldedView; experimental; // until FoldedView becomes a TSynEditStringsLinked
end;
{ TSynEditCaret }
@ -2321,7 +2318,7 @@ begin
Value.y := MinMax(Value.y, 1, Max(fLines.Count, 1));
// ensure folded block at bottom line is in selection
if (ActiveSelectionMode = smLine) and (FFoldedView <> nil) and
if (ActiveSelectionMode = smLine) and (FLines <> nil) and
(FAutoExtend or FStickyAutoExtend)
then begin
if ( (FStartLinePos > Value.y) or
@ -2329,10 +2326,10 @@ begin
) and
(not SelAvail)
then
FStartLinePos := TSynEditFoldedView(FFoldedView).TextPosAddLines(FStartLinePos, 1) - 1
FStartLinePos := ToPos(FLines.AddVisibleOffsetToTextIndex(ToIdx(FStartLinePos), 1)) - 1
else
if (Value.y < fLines.Count) then
Value.y := TSynEditFoldedView(FFoldedView).TextPosAddLines(Value.y, 1) - 1;
Value.y := ToPos(FLines.AddVisibleOffsetToTextIndex(ToIdx(Value.y), 1)) - 1;
end;
if (FCaret = nil) or FCaret.AllowPastEOL then
@ -2403,9 +2400,9 @@ begin
// only when selection is new (WasAvail = False)
if SelAvail and (FAutoExtend or FStickyAutoExtend) then begin
if IsBackwardSel then
FStartLinePos := TSynEditFoldedView(FFoldedView).TextPosAddLines(FStartLinePos, 1) - 1
FStartLinePos := ToPos(FLines.AddVisibleOffsetToTextIndex(ToIdx(FStartLinePos), 1)) - 1
else
FEndLinePos := TSynEditFoldedView(FFoldedView).TextPosAddLines(FEndLinePos, 1) - 1;
FEndLinePos := ToPos(FLines.AddVisibleOffsetToTextIndex(ToIdx(FEndLinePos), 1)) - 1;
end;
FInvalidateLinesMethod(Min(FStartLinePos, FEndLinePos),
Max(FStartLinePos, FEndLinePos) );