SynEdit: Markup, fix markup for empty line-part after wrap-pos

git-svn-id: trunk@63294 -
This commit is contained in:
martin 2020-06-05 00:12:59 +00:00
parent 47a4815c09
commit 680762bdbf
4 changed files with 98 additions and 7 deletions

View File

@ -64,6 +64,7 @@ type
FCurViewToken: TLazSynDisplayTokenInfo; FCurViewToken: TLazSynDisplayTokenInfo;
FCurViewCurTokenStartPos: TLazSynDisplayTokenBound; // Start bound of the HL token FCurViewCurTokenStartPos: TLazSynDisplayTokenBound; // Start bound of the HL token
FCurViewAttr: TSynSelectedColorMergeResult; FCurViewAttr: TSynSelectedColorMergeResult;
FWrapEndBound: TLazSynDisplayTokenBound;
// Scanner Pos // Scanner Pos
FCurViewScannerPos: TLazSynDisplayTokenBound; // Start according to Logical flow. Left for LTR, or Right for RTL FCurViewScannerPos: TLazSynDisplayTokenBound; // Start according to Logical flow. Left for LTR, or Right for RTL
FCurViewScannerPhysCharPos: Integer; // 1 based - Full char bound (Before FCurViewScannerPos.Physical (PaintStart)) FCurViewScannerPhysCharPos: Integer; // 1 based - Full char bound (Before FCurViewScannerPos.Physical (PaintStart))
@ -78,7 +79,7 @@ type
FNextMarkupPhysPos, FNextMarkupLogPos: Integer; FNextMarkupPhysPos, FNextMarkupLogPos: Integer;
FCurMarkupNextStart: TLazSynDisplayTokenBound; FCurMarkupNextStart: TLazSynDisplayTokenBound;
FCurMarkupNextRtlInfo: TLazSynDisplayRtlInfo; FCurMarkupNextRtlInfo: TLazSynDisplayRtlInfo;
FCurMarkupState: (cmPreInit, cmLine, cmPastEOL); FCurMarkupState: (cmPreInit, cmLine, cmPastEOL, cmPastWrapEnd);
FMarkupTokenAttr: TSynSelectedColorMergeResult; FMarkupTokenAttr: TSynSelectedColorMergeResult;
procedure InitCurMarkup; procedure InitCurMarkup;
public public
@ -340,6 +341,20 @@ begin
if FCurMarkupState = cmPreInit then if FCurMarkupState = cmPreInit then
InitCurMarkup; InitCurMarkup;
if (FCurLineByteLen < FCharWidthsLen) and (FCurViewScannerPos.Logical > FCurLineByteLen)
then begin
if FCurMarkupState <> cmPastWrapEnd then begin
assert(FCurViewScannerPos.Logical = FCurLineByteLen + 1, 'TLazSynPaintTokenBreaker.GetNextHighlighterTokenEx: FCurViewScannerPos.Logical = FCurLineByteLen + 1');
FCurMarkupState := cmPastWrapEnd;
FWrapEndBound := FCurViewScannerPos;
end;
end;
if (FCurMarkupState = cmPastWrapEnd) then begin
FNextMarkupPhysPos := MaxInt;
FNextMarkupLogPos := MaxInt;
end
else
if (FNextMarkupPhysPos < 0) or if (FNextMarkupPhysPos < 0) or
(FCurMarkupNextRtlInfo.IsRtl and (FNextMarkupPhysPos >= FCurMarkupNextStart.Physical)) or (FCurMarkupNextRtlInfo.IsRtl and (FNextMarkupPhysPos >= FCurMarkupNextStart.Physical)) or
((not FCurMarkupNextRtlInfo.IsRtl) and (FNextMarkupPhysPos <= FCurMarkupNextStart.Physical)) or ((not FCurMarkupNextRtlInfo.IsRtl) and (FNextMarkupPhysPos <= FCurMarkupNextStart.Physical)) or
@ -356,14 +371,19 @@ begin
FNextMarkupLogPos := MaxInt; FNextMarkupLogPos := MaxInt;
end; end;
if (FCurMarkupState <> cmPastWrapEnd) and (FCurLineByteLen < FCharWidthsLen) and
(FNextMarkupLogPos > FCurLineByteLen + 1)
then
FNextMarkupLogPos := FCurLineByteLen + 1; // stop at WrapEnd / EOL // tokens should have a bound there anyway
ATokenInfo.Attr := nil; ATokenInfo.Attr := nil;
if FCurMarkupState = cmPastEOL if FCurMarkupState in [cmPastEOL, cmPastWrapEnd]
then Result := False then Result := False
else Result := GetNextHighlighterTokenFromView(ATokenInfo, FNextMarkupPhysPos, FNextMarkupLogPos); else Result := GetNextHighlighterTokenFromView(ATokenInfo, FNextMarkupPhysPos, FNextMarkupLogPos);
if (not Result) then begin if not Result then begin
// the first run StartPos is set by GetNextHighlighterTokenFromView // the first run StartPos is set by GetNextHighlighterTokenFromView
if FCurMarkupState = cmPastEOL then begin if FCurMarkupState in [cmPastEOL, cmPastWrapEnd] then begin
ATokenInfo.StartPos := FCurMarkupNextStart ATokenInfo.StartPos := FCurMarkupNextStart
end end
else else
@ -372,7 +392,8 @@ begin
ATokenInfo.StartPos.Physical := FFirstCol; ATokenInfo.StartPos.Physical := FFirstCol;
end; end;
FCurMarkupState := cmPastEOL; if (FCurMarkupState <> cmPastWrapEnd) then
FCurMarkupState := cmPastEOL;
Result := (ATokenInfo.StartPos.Physical < FLastCol); Result := (ATokenInfo.StartPos.Physical < FLastCol);
if not Result then if not Result then
@ -433,8 +454,12 @@ begin
FMarkupTokenAttr.CurrentEndX := ATokenInfo.EndPos; FMarkupTokenAttr.CurrentEndX := ATokenInfo.EndPos;
end; end;
fMarkupManager.MergeMarkupAttributeAtRowCol(FCurTxtLineIdx + 1, if FCurMarkupState = cmPastWrapEnd then
ATokenInfo.StartPos, ATokenInfo.EndPos, ATokenInfo.RtlInfo, FMarkupTokenAttr); fMarkupManager.MergeMarkupAttributeAtWrapEnd(FCurTxtLineIdx + 1,
FWrapEndBound, FMarkupTokenAttr)
else
fMarkupManager.MergeMarkupAttributeAtRowCol(FCurTxtLineIdx + 1,
ATokenInfo.StartPos, ATokenInfo.EndPos, ATokenInfo.RtlInfo, FMarkupTokenAttr);
FMarkupTokenAttr.ProcessMergeInfo; FMarkupTokenAttr.ProcessMergeInfo;

View File

@ -116,6 +116,14 @@ type
const AnRtlInfo: TLazSynDisplayRtlInfo; const AnRtlInfo: TLazSynDisplayRtlInfo;
AMarkup: TSynSelectedColorMergeResult); virtual; AMarkup: TSynSelectedColorMergeResult); virtual;
function GetMarkupAttributeAtWrapEnd(const aRow: Integer;
const aWrapCol: TLazSynDisplayTokenBound): TSynSelectedColor; virtual;
// experimental; // params may still change
procedure MergeMarkupAttributeAtWrapEnd(const aRow: Integer;
const aWrapCol: TLazSynDisplayTokenBound;
AMarkup: TSynSelectedColorMergeResult); virtual;
// experimental; // params may still change
// Notifications about Changes to the text // Notifications about Changes to the text
Procedure TextChanged(aFirstCodeLine, aLastCodeLine, ACountDiff: Integer); virtual; // 1 based Procedure TextChanged(aFirstCodeLine, aLastCodeLine, ACountDiff: Integer); virtual; // 1 based
Procedure TempDisable; Procedure TempDisable;
@ -183,6 +191,10 @@ type
const AnRtlInfo: TLazSynDisplayRtlInfo; const AnRtlInfo: TLazSynDisplayRtlInfo;
AMarkup: TSynSelectedColorMergeResult); override; AMarkup: TSynSelectedColorMergeResult); override;
procedure MergeMarkupAttributeAtWrapEnd(const aRow: Integer;
const aWrapCol: TLazSynDisplayTokenBound;
AMarkup: TSynSelectedColorMergeResult); override;
// Notifications about Changes to the text // Notifications about Changes to the text
Procedure TextChanged(aFirstCodeLine, aLastCodeLine, ACountDiff: Integer); override; // lines are 1 based Procedure TextChanged(aFirstCodeLine, aLastCodeLine, ACountDiff: Integer); override; // lines are 1 based
end; end;
@ -449,6 +461,23 @@ begin
AMarkup.Merge(c, aStartCol, AEndCol); AMarkup.Merge(c, aStartCol, AEndCol);
end; end;
function TSynEditMarkup.GetMarkupAttributeAtWrapEnd(const aRow: Integer;
const aWrapCol: TLazSynDisplayTokenBound): TSynSelectedColor;
begin
Result := nil;
end;
procedure TSynEditMarkup.MergeMarkupAttributeAtWrapEnd(const aRow: Integer;
const aWrapCol: TLazSynDisplayTokenBound;
AMarkup: TSynSelectedColorMergeResult);
var
c: TSynSelectedColor;
begin
c := GetMarkupAttributeAtWrapEnd(aRow, aWrapCol);
if assigned(c) then
AMarkup.Merge(c);
end;
procedure TSynEditMarkup.TextChanged(aFirstCodeLine, aLastCodeLine, ACountDiff: Integer); procedure TSynEditMarkup.TextChanged(aFirstCodeLine, aLastCodeLine, ACountDiff: Integer);
begin begin
DoTextChanged(aFirstCodeLine, aLastCodeLine, ACountDiff); DoTextChanged(aFirstCodeLine, aLastCodeLine, ACountDiff);
@ -601,6 +630,19 @@ begin
end; end;
end; end;
procedure TSynEditMarkupManager.MergeMarkupAttributeAtWrapEnd(
const aRow: Integer; const aWrapCol: TLazSynDisplayTokenBound;
AMarkup: TSynSelectedColorMergeResult);
var
i : integer;
begin
for i := 0 to fMarkUpList.Count-1 do begin
if TSynEditMarkup(fMarkUpList[i]).RealEnabled then
TSynEditMarkup(fMarkUpList[i]).MergeMarkupAttributeAtWrapEnd
(aRow, aWrapCol, AMarkup);
end;
end;
function TSynEditMarkupManager.GetMarkupAttributeAtRowCol(const aRow: Integer; function TSynEditMarkupManager.GetMarkupAttributeAtRowCol(const aRow: Integer;
const aStartCol: TLazSynDisplayTokenBound; const aStartCol: TLazSynDisplayTokenBound;
const AnRtlInfo: TLazSynDisplayRtlInfo): TSynSelectedColor; const AnRtlInfo: TLazSynDisplayRtlInfo): TSynSelectedColor;

View File

@ -59,6 +59,8 @@ type
const aStartCol: TLazSynDisplayTokenBound; const aStartCol: TLazSynDisplayTokenBound;
const AnRtlInfo: TLazSynDisplayRtlInfo; const AnRtlInfo: TLazSynDisplayRtlInfo;
out ANextPhys, ANextLog: Integer); override; out ANextPhys, ANextLog: Integer); override;
function GetMarkupAttributeAtWrapEnd(const aRow: Integer;
const aWrapCol: TLazSynDisplayTokenBound): TSynSelectedColor; override;
property ColorTillEol: boolean read FColorTillEol write SetColorTillEol; property ColorTillEol: boolean read FColorTillEol write SetColorTillEol;
property UseIncrementalColor : Boolean read FUseIncrementalColor write SetUseIncrementalColor; property UseIncrementalColor : Boolean read FUseIncrementalColor write SetUseIncrementalColor;
@ -212,6 +214,16 @@ begin
//end; //end;
end; end;
function TSynEditMarkupSelection.GetMarkupAttributeAtWrapEnd(
const aRow: Integer; const aWrapCol: TLazSynDisplayTokenBound
): TSynSelectedColor;
begin
result := nil;
if (nSelStart <= aWrapCol.Logical) and ((nSelEnd > aWrapCol.Logical) or (nSelEnd < 0)) then
Result := MarkupInfo;
end;
procedure TSynEditMarkupSelection.GetNextMarkupColAfterRowCol(const aRow: Integer; procedure TSynEditMarkupSelection.GetNextMarkupColAfterRowCol(const aRow: Integer;
const aStartCol: TLazSynDisplayTokenBound; const AnRtlInfo: TLazSynDisplayRtlInfo; out ANextPhys, const aStartCol: TLazSynDisplayTokenBound; const AnRtlInfo: TLazSynDisplayRtlInfo; out ANextPhys,
ANextLog: Integer); ANextLog: Integer);

View File

@ -65,6 +65,8 @@ type
const aStartCol: TLazSynDisplayTokenBound; const aStartCol: TLazSynDisplayTokenBound;
const AnRtlInfo: TLazSynDisplayRtlInfo; const AnRtlInfo: TLazSynDisplayRtlInfo;
out ANextPhys, ANextLog: Integer); override; out ANextPhys, ANextLog: Integer); override;
function GetMarkupAttributeAtWrapEnd(const aRow: Integer;
const aWrapCol: TLazSynDisplayTokenBound): TSynSelectedColor; override;
function RealEnabled: Boolean; override; function RealEnabled: Boolean; override;
procedure InvalidateLineHighlight; procedure InvalidateLineHighlight;
@ -209,6 +211,16 @@ begin
ANextPhys := -1; // always valid for the whole line ANextPhys := -1; // always valid for the whole line
end; end;
function TSynEditMarkupSpecialLine.GetMarkupAttributeAtWrapEnd(
const aRow: Integer; const aWrapCol: TLazSynDisplayTokenBound
): TSynSelectedColor;
begin
Result := nil;
MarkupInfo.SetFrameBoundsPhys(1, MaxInt);
if FSpecialLine then
Result := MarkupInfo;
end;
procedure TSynEditMarkupSpecialLine.InvalidateLineHighlight; procedure TSynEditMarkupSpecialLine.InvalidateLineHighlight;
var var
NewLine: Integer; NewLine: Integer;