Add ViewedLineCharPos to caret class

git-svn-id: trunk@63268 -
This commit is contained in:
martin 2020-06-02 00:37:13 +00:00
parent a5b0880676
commit 0530c0faf1

View File

@ -120,6 +120,9 @@ type
FAltStartLinePos, FAltStartBytePos: Integer; // 1 based // Alternate, for min selection FAltStartLinePos, FAltStartBytePos: Integer; // 1 based // Alternate, for min selection
FEndLinePos: Integer; // 1 based FEndLinePos: Integer; // 1 based
FEndBytePos: Integer; // 1 based FEndBytePos: Integer; // 1 based
FViewedFirstStartLineCharPos: TPoint; // 1 based
FViewedLastEndLineCharPos: TPoint; // 1 based
FFLags: set of (sbViewedFirstPosValid, sbViewedLastPosValid, sbHasLineMapHandler);
FLeftCharPos: Integer; FLeftCharPos: Integer;
FRightCharPos: Integer; FRightCharPos: Integer;
FPersistent: Boolean; FPersistent: Boolean;
@ -132,6 +135,8 @@ type
FLastCarePos: TPoint; FLastCarePos: TPoint;
FStickyAutoExtend: Boolean; FStickyAutoExtend: Boolean;
function AdjustBytePosToCharacterStart(Line: integer; BytePos: integer): integer; function AdjustBytePosToCharacterStart(Line: integer; BytePos: integer): integer;
procedure DoLinesMappingChanged(Sender: TSynEditStrings; aIndex,
aCount: Integer);
function GetColumnEndBytePos(ALinePos: Integer): integer; function GetColumnEndBytePos(ALinePos: Integer): integer;
function GetColumnStartBytePos(ALinePos: Integer): integer; function GetColumnStartBytePos(ALinePos: Integer): integer;
function GetFirstLineBytePos: TPoint; function GetFirstLineBytePos: TPoint;
@ -139,6 +144,8 @@ type
function GetLastLineHasSelection: Boolean; function GetLastLineHasSelection: Boolean;
function GetColumnLeftCharPos: Integer; function GetColumnLeftCharPos: Integer;
function GetColumnRightCharPos: Integer; function GetColumnRightCharPos: Integer;
function GetViewedFirstLineCharPos: TPoint;
function GetViewedLastLineCharPos: TPoint;
procedure SetAutoExtend(AValue: Boolean); procedure SetAutoExtend(AValue: Boolean);
procedure SetCaret(const AValue: TSynEditCaret); procedure SetCaret(const AValue: TSynEditCaret);
procedure SetEnabled(const Value : Boolean); procedure SetEnabled(const Value : Boolean);
@ -202,6 +209,8 @@ type
// First and Last Pos are ordered according to the text flow (LTR) // First and Last Pos are ordered according to the text flow (LTR)
property FirstLineBytePos: TPoint read GetFirstLineBytePos; property FirstLineBytePos: TPoint read GetFirstLineBytePos;
property LastLineBytePos: TPoint read GetLastLineBytePos; property LastLineBytePos: TPoint read GetLastLineBytePos;
property ViewedFirstLineCharPos: TPoint read GetViewedFirstLineCharPos;
property ViewedLastLineCharPos: TPoint read GetViewedLastLineCharPos;
// For column mode selection: Phys-Char pos of left and right side. (Start/End could each be either left or right) // For column mode selection: Phys-Char pos of left and right side. (Start/End could each be either left or right)
property ColumnLeftCharPos: Integer read GetColumnLeftCharPos; property ColumnLeftCharPos: Integer read GetColumnLeftCharPos;
property ColumnRightCharPos: Integer read GetColumnRightCharPos; property ColumnRightCharPos: Integer read GetColumnRightCharPos;
@ -222,7 +231,8 @@ type
{ TSynEditCaret } { TSynEditCaret }
TSynEditCaretFlag = ( TSynEditCaretFlag = (
scCharPosValid, scBytePosValid scCharPosValid, scBytePosValid, scViewedPosValid,
scHasLineMapHandler
); );
TSynEditCaretFlags = set of TSynEditCaretFlag; TSynEditCaretFlags = set of TSynEditCaretFlag;
@ -245,13 +255,17 @@ type
FLinePos: Integer; // 1 based FLinePos: Integer; // 1 based
FCharPos: Integer; // 1 based FCharPos: Integer; // 1 based
FBytePos, FBytePosOffset: Integer; // 1 based FBytePos, FBytePosOffset: Integer; // 1 based
FViewedLineCharPos: TPoint;
procedure DoLinesMappingChanged(Sender: TSynEditStrings; aIndex,
aCount: Integer);
function GetBytePos: Integer; function GetBytePos: Integer;
function GetBytePosOffset: Integer; function GetBytePosOffset: Integer;
function GetCharPos: Integer; function GetCharPos: Integer;
function GetFullLogicalPos: TLogCaretPoint; function GetFullLogicalPos: TLogCaretPoint;
function GetLineBytePos: TPoint; function GetLineBytePos: TPoint;
function GetLineCharPos: TPoint; function GetLineCharPos: TPoint;
function GetViewedLineCharPos: TPoint;
procedure SetBytePos(AValue: Integer); procedure SetBytePos(AValue: Integer);
procedure SetBytePosOffset(AValue: Integer); procedure SetBytePosOffset(AValue: Integer);
procedure SetCharPos(AValue: Integer); procedure SetCharPos(AValue: Integer);
@ -289,6 +303,7 @@ type
property BytePosOffset: Integer read GetBytePosOffset write SetBytePosOffset; property BytePosOffset: Integer read GetBytePosOffset write SetBytePosOffset;
property LineBytePos: TPoint read GetLineBytePos write SetLineBytePos; property LineBytePos: TPoint read GetLineBytePos write SetLineBytePos;
property FullLogicalPos: TLogCaretPoint read GetFullLogicalPos write SetFullLogicalPos; property FullLogicalPos: TLogCaretPoint read GetFullLogicalPos write SetFullLogicalPos;
property ViewedLineCharPos: TPoint read GetViewedLineCharPos;
property LineText: string read GetLineText write SetLineText; property LineText: string read GetLineText write SetLineText;
end; end;
@ -642,6 +657,12 @@ begin
Result := FBytePos; Result := FBytePos;
end; end;
procedure TSynEditBaseCaret.DoLinesMappingChanged(Sender: TSynEditStrings;
aIndex, aCount: Integer);
begin
Exclude(FFlags, scViewedPosValid);
end;
function TSynEditBaseCaret.GetBytePosOffset: Integer; function TSynEditBaseCaret.GetBytePosOffset: Integer;
begin begin
ValidateBytePos; ValidateBytePos;
@ -674,6 +695,18 @@ begin
Result := Point(FCharPos, FLinePos); Result := Point(FCharPos, FLinePos);
end; end;
function TSynEditBaseCaret.GetViewedLineCharPos: TPoint;
begin
if not(scViewedPosValid in FFlags) then
FViewedLineCharPos := Lines.TextXYToViewXY(LineCharPos);
include(FFlags, scViewedPosValid);
Result := FViewedLineCharPos;
if scHasLineMapHandler in FFlags then begin
Lines.AddChangeHandler(senrLineMappingChanged, @DoLinesMappingChanged);
Include(FFlags, scHasLineMapHandler);
end;
end;
procedure TSynEditBaseCaret.SetBytePos(AValue: Integer); procedure TSynEditBaseCaret.SetBytePos(AValue: Integer);
begin begin
InternalSetLineByterPos(FLinePos, AValue, 0, [scuChangedX]); InternalSetLineByterPos(FLinePos, AValue, 0, [scuChangedX]);
@ -768,17 +801,17 @@ begin
exit; exit;
if not (scuNoInvalidate in UpdFlags) then if not (scuNoInvalidate in UpdFlags) then
Exclude(FFlags, scBytePosValid); FFlags := FFlags - [scBytePosValid, scViewedPosValid];
Include(FFlags, scCharPosValid); Include(FFlags, scCharPosValid);
if NewLine < 1 then begin if NewLine < 1 then begin
NewLine := 1; NewLine := 1;
Exclude(FFlags, scBytePosValid); FFlags := FFlags - [scBytePosValid, scViewedPosValid];
end; end;
if NewCharPos < 1 then begin if NewCharPos < 1 then begin
NewCharPos := 1; NewCharPos := 1;
Exclude(FFlags, scBytePosValid); FFlags := FFlags - [scBytePosValid, scViewedPosValid];
end; end;
FCharPos := NewCharPos; FCharPos := NewCharPos;
@ -794,17 +827,17 @@ begin
exit; exit;
if not (scuNoInvalidate in UpdFlags) then if not (scuNoInvalidate in UpdFlags) then
Exclude(FFlags, scCharPosValid); FFlags := FFlags - [scCharPosValid, scViewedPosValid];
Include(FFlags, scBytePosValid); Include(FFlags, scBytePosValid);
if NewLine < 1 then begin if NewLine < 1 then begin
NewLine := 1; NewLine := 1;
Exclude(FFlags, scCharPosValid); FFlags := FFlags - [scCharPosValid, scViewedPosValid];
end; end;
if NewBytePos < 1 then begin if NewBytePos < 1 then begin
NewBytePos := 1; NewBytePos := 1;
Exclude(FFlags, scCharPosValid); FFlags := FFlags - [scCharPosValid, scViewedPosValid];
end; end;
FBytePos := NewBytePos; FBytePos := NewBytePos;
@ -829,6 +862,7 @@ begin
FBytePos := Src.FBytePos; FBytePos := Src.FBytePos;
FBytePosOffset := Src.FBytePosOffset; FBytePosOffset := Src.FBytePosOffset;
FFlags := Src.FFlags; FFlags := Src.FFlags;
Exclude(FFlags, scViewedPosValid); // Or check that an senrLineMappingChanged handler exists
SetLines(Src.FLines); SetLines(Src.FLines);
end; end;
@ -853,7 +887,7 @@ begin
if not (scBytePosValid in FFlags) then if not (scBytePosValid in FFlags) then
Invalidate Invalidate
else else
Exclude(FFlags, scCharPosValid); FFlags := FFlags - [scCharPosValid, scViewedPosValid];
end; end;
function TSynEditBaseCaret.IsAtLineChar(aPoint: TPoint): Boolean; function TSynEditBaseCaret.IsAtLineChar(aPoint: TPoint): Boolean;
@ -2463,6 +2497,12 @@ begin
if Result <> BytePos then debugln(['Selection needed byte adjustment Line=', Line, ' BytePos=', BytePos, ' Result=', Result]); if Result <> BytePos then debugln(['Selection needed byte adjustment Line=', Line, ' BytePos=', BytePos, ' Result=', Result]);
end; end;
procedure TSynEditSelection.DoLinesMappingChanged(Sender: TSynEditStrings;
aIndex, aCount: Integer);
begin
FFlags := FFLags - [sbViewedFirstPosValid, sbViewedLastPosValid];
end;
function TSynEditSelection.GetColumnEndBytePos(ALinePos: Integer): integer; function TSynEditSelection.GetColumnEndBytePos(ALinePos: Integer): integer;
begin begin
FInternalCaret.Invalidate; FInternalCaret.Invalidate;
@ -2526,6 +2566,35 @@ begin
Result := FRightCharPos; Result := FRightCharPos;
end; end;
function TSynEditSelection.GetViewedFirstLineCharPos: TPoint;
begin
if not(sbViewedFirstPosValid in FFlags) then
FViewedFirstStartLineCharPos := Lines.TextXYToViewXY(
Lines.LogicalToPhysicalPos(FirstLineBytePos)
);
include(FFlags, sbViewedFirstPosValid);
Result := FViewedFirstStartLineCharPos;
if sbHasLineMapHandler in FFlags then begin
Lines.AddChangeHandler(senrLineMappingChanged, @DoLinesMappingChanged);
Include(FFlags, sbHasLineMapHandler);
end;
end;
function TSynEditSelection.GetViewedLastLineCharPos: TPoint;
begin
if not(sbViewedLastPosValid in FFlags) then
FViewedLastEndLineCharPos := Lines.TextXYToViewXY(
Lines.LogicalToPhysicalPos(LastLineBytePos)
);
include(FFlags, sbViewedLastPosValid);
Result := FViewedLastEndLineCharPos;
if sbHasLineMapHandler in FFlags then begin
Lines.AddChangeHandler(senrLineMappingChanged, @DoLinesMappingChanged);
Include(FFlags, sbHasLineMapHandler);
end;
end;
procedure TSynEditSelection.SetAutoExtend(AValue: Boolean); procedure TSynEditSelection.SetAutoExtend(AValue: Boolean);
begin begin
if FAutoExtend = AValue then Exit; if FAutoExtend = AValue then Exit;