SynEdit: WrappedView, add some MarkupColors

This commit is contained in:
Martin 2025-02-12 18:37:01 +01:00
parent 5a2dab70e4
commit 43b194714e

View File

@ -185,9 +185,10 @@ type
FCurToken: TLazSynDisplayTokenInfo; FCurToken: TLazSynDisplayTokenInfo;
FCurLineLogIdx: Integer; FCurLineLogIdx: Integer;
FCurLineWrapIndentString: String; FCurLineWrapIndentString: String;
FCurrentSubLineMarkupInfo: TSynSelectedColorMergeResult;
public public
constructor Create(AWrappedView: TSynEditLineMappingView; AWrapPlugin: TLazSynEditLineWrapPlugin); constructor Create(AWrappedView: TSynEditLineMappingView; AWrapPlugin: TLazSynEditLineWrapPlugin);
//destructor Destroy; override; destructor Destroy; override;
procedure SetHighlighterTokensLine(AWrappedLine: TLineIdx; out procedure SetHighlighterTokensLine(AWrappedLine: TLineIdx; out
ARealLine: TLineIdx; out ASubLineIdx, AStartBytePos, AStartPhysPos, ALineByteLen: Integer); override; ARealLine: TLineIdx; out ASubLineIdx, AStartBytePos, AStartPhysPos, ALineByteLen: Integer); override;
function GetNextHighlighterToken(out ATokenInfo: TLazSynDisplayTokenInfo): Boolean; override; function GetNextHighlighterToken(out ATokenInfo: TLazSynDisplayTokenInfo): Boolean; override;
@ -199,6 +200,10 @@ type
private private
FCurrentWrapColumn: Integer; FCurrentWrapColumn: Integer;
FCaretWrapPos: TLazSynEditWrapCaretPos; FCaretWrapPos: TLazSynEditWrapCaretPos;
FMarkupInfoWrapEol: TSynSelectedColor;
FMarkupInfoWrapIndent: TSynSelectedColor;
FMarkupInfoWrapSubLine: TSynSelectedColor;
FMinWrapWidth: Integer; FMinWrapWidth: Integer;
FWrapIndentMaxAbs: Integer; FWrapIndentMaxAbs: Integer;
FWrapIndentMaxRel: Integer; FWrapIndentMaxRel: Integer;
@ -206,6 +211,7 @@ type
FWrapIndentIsOffset: Boolean; FWrapIndentIsOffset: Boolean;
FWrapIndentWidth: Integer; FWrapIndentWidth: Integer;
procedure DoLinesChanged(Sender: TObject); procedure DoLinesChanged(Sender: TObject);
procedure DoMarkupChanged(Sender: TObject);
procedure DoWidthChanged(Sender: TObject; Changes: TSynStatusChanges); procedure DoWidthChanged(Sender: TObject; Changes: TSynStatusChanges);
function GetWrapColumn: Integer; function GetWrapColumn: Integer;
@ -254,6 +260,10 @@ public
property WrapIndentMinAbs: Integer read FWrapIndentMinAbs write SetWrapIndentMinAbs; property WrapIndentMinAbs: Integer read FWrapIndentMinAbs write SetWrapIndentMinAbs;
property WrapIndentMaxAbs: Integer read FWrapIndentMaxAbs write SetWrapIndentMaxAbs; property WrapIndentMaxAbs: Integer read FWrapIndentMaxAbs write SetWrapIndentMaxAbs;
property WrapIndentMaxRel: Integer read FWrapIndentMaxRel write SetWrapIndentMaxRel; property WrapIndentMaxRel: Integer read FWrapIndentMaxRel write SetWrapIndentMaxRel;
property MarkupInfoWrapSubLine: TSynSelectedColor read FMarkupInfoWrapSubLine;
property MarkupInfoWrapIndent: TSynSelectedColor read FMarkupInfoWrapIndent;
property MarkupInfoWrapEol: TSynSelectedColor read FMarkupInfoWrapEol;
end; end;
implementation implementation
@ -1498,9 +1508,16 @@ constructor TLazSynDisplayWordWrap.Create(AWrappedView: TSynEditLineMappingView;
AWrapPlugin: TLazSynEditLineWrapPlugin); AWrapPlugin: TLazSynEditLineWrapPlugin);
begin begin
FWrapPlugin := AWrapPlugin; FWrapPlugin := AWrapPlugin;
FCurrentSubLineMarkupInfo := TSynSelectedColorMergeResult.Create(nil);
inherited Create(AWrappedView); inherited Create(AWrappedView);
end; end;
destructor TLazSynDisplayWordWrap.Destroy;
begin
FCurrentSubLineMarkupInfo.Free;
inherited Destroy;
end;
procedure TLazSynDisplayWordWrap.SetHighlighterTokensLine( procedure TLazSynDisplayWordWrap.SetHighlighterTokensLine(
AWrappedLine: TLineIdx; out ARealLine: TLineIdx; out ASubLineIdx, AStartBytePos, AWrappedLine: TLineIdx; out ARealLine: TLineIdx; out ASubLineIdx, AStartBytePos,
AStartPhysPos, ALineByteLen: Integer); AStartPhysPos, ALineByteLen: Integer);
@ -1553,13 +1570,14 @@ function TLazSynDisplayWordWrap.GetNextHighlighterToken(out
ATokenInfo: TLazSynDisplayTokenInfo): Boolean; ATokenInfo: TLazSynDisplayTokenInfo): Boolean;
var var
PreStart: Integer; PreStart: Integer;
LineBnd1, LineBnd2: TLazSynDisplayTokenBound;
begin begin
ATokenInfo := Default(TLazSynDisplayTokenInfo); ATokenInfo := Default(TLazSynDisplayTokenInfo);
if FCurLineLogIdx < 0 then begin if FCurLineLogIdx < 0 then begin
Result := True; Result := True;
ATokenInfo.TokenStart := PChar(FCurLineWrapIndentString); ATokenInfo.TokenStart := PChar(FCurLineWrapIndentString);
ATokenInfo.TokenLength := -FCurLineLogIdx; ATokenInfo.TokenLength := -FCurLineLogIdx;
ATokenInfo.TokenAttr := nil; ATokenInfo.TokenAttr := FWrapPlugin.MarkupInfoWrapIndent;
ATokenInfo.TokenOrigin := dtoBeforeText; ATokenInfo.TokenOrigin := dtoBeforeText;
FCurLineLogIdx := 0; FCurLineLogIdx := 0;
exit; exit;
@ -1567,6 +1585,7 @@ begin
If (FCurLineLogIdx >= FCurSubLineNextLogStartIdx) and (FCurSubLineNextLogStartIdx < FCurRealLineByteLen) then begin If (FCurLineLogIdx >= FCurSubLineNextLogStartIdx) and (FCurSubLineNextLogStartIdx < FCurRealLineByteLen) then begin
ATokenInfo.TokenOrigin := dtoAfterWrapped; ATokenInfo.TokenOrigin := dtoAfterWrapped;
ATokenInfo.TokenAttr := FWrapPlugin.MarkupInfoWrapEol;
Result := True; // TokenStart = nil => no text Result := True; // TokenStart = nil => no text
exit; exit;
end; end;
@ -1588,6 +1607,7 @@ begin
Result := ATokenInfo.TokenLength > 0; Result := ATokenInfo.TokenLength > 0;
if not Result then begin if not Result then begin
ATokenInfo.TokenOrigin := dtoAfterWrapped; ATokenInfo.TokenOrigin := dtoAfterWrapped;
ATokenInfo.TokenAttr := FWrapPlugin.MarkupInfoWrapEol;
Result := False; Result := False;
exit; exit;
end; end;
@ -1599,10 +1619,31 @@ begin
Result := ATokenInfo.TokenLength > 0; Result := ATokenInfo.TokenLength > 0;
if not Result then begin if not Result then begin
ATokenInfo.TokenOrigin := dtoAfterWrapped; ATokenInfo.TokenOrigin := dtoAfterWrapped;
ATokenInfo.TokenAttr := FWrapPlugin.MarkupInfoWrapEol;
Result := False; Result := False;
exit; exit;
end; end;
end; end;
if (FCurrentWrapSubline > 0) and (FWrapPlugin.MarkupInfoWrapSubLine <> nil) and
(FWrapPlugin.MarkupInfoWrapSubLine.IsEnabled)
then begin
LineBnd1.Logical := ToPos(FCurSubLineLogStartIdx);
LineBnd1.Physical := -1;
LineBnd1.Offset := 0;
LineBnd2.Logical := ToPos(FCurSubLineNextLogStartIdx);
LineBnd2.Physical := -1;
LineBnd2.Offset := 0;
FCurrentSubLineMarkupInfo.Clear;
if ATokenInfo.TokenAttr <> nil then begin
FCurrentSubLineMarkupInfo.Assign(ATokenInfo.TokenAttr);
FCurrentSubLineMarkupInfo.Merge(FWrapPlugin.MarkupInfoWrapSubLine, LineBnd1, LineBnd2);
end
else
FCurrentSubLineMarkupInfo.Assign(FWrapPlugin.MarkupInfoWrapSubLine);
ATokenInfo.TokenAttr := FCurrentSubLineMarkupInfo;
end;
end; end;
{ TLazSynEditLineWrapPlugin } { TLazSynEditLineWrapPlugin }
@ -1612,6 +1653,11 @@ begin
ValidateAll; ValidateAll;
end; end;
procedure TLazSynEditLineWrapPlugin.DoMarkupChanged(Sender: TObject);
begin
FMarkupInfoWrapIndent.FrameEdges := sfeLeft;
end;
procedure TLazSynEditLineWrapPlugin.DoWidthChanged(Sender: TObject; procedure TLazSynEditLineWrapPlugin.DoWidthChanged(Sender: TObject;
Changes: TSynStatusChanges); Changes: TSynStatusChanges);
var var
@ -1979,6 +2025,16 @@ end;
constructor TLazSynEditLineWrapPlugin.Create(AOwner: TComponent); constructor TLazSynEditLineWrapPlugin.Create(AOwner: TComponent);
begin begin
inherited Create(AOwner); inherited Create(AOwner);
FMarkupInfoWrapSubLine := TSynSelectedColor.Create;
FMarkupInfoWrapIndent := TSynSelectedColor.Create;
FMarkupInfoWrapEol := TSynSelectedColor.Create;
FMarkupInfoWrapSubLine.Clear;
FMarkupInfoWrapIndent.Clear;
FMarkupInfoWrapEol.Clear;
FMarkupInfoWrapIndent.FrameEdges := sfeLeft;
FMarkupInfoWrapIndent.OnChange := @DoMarkupChanged;
FLineMapView := TSynEditLineMappingView(TSynEdit(Editor).TextViewsManager.SynTextViewByClass[TSynEditLineMappingView]); FLineMapView := TSynEditLineMappingView(TSynEdit(Editor).TextViewsManager.SynTextViewByClass[TSynEditLineMappingView]);
if FLineMapView = nil then begin if FLineMapView = nil then begin
FLineMapView := TSynEditLineMappingView.Create; FLineMapView := TSynEditLineMappingView.Create;
@ -2010,6 +2066,10 @@ begin
end; end;
end; end;
inherited Destroy; inherited Destroy;
FMarkupInfoWrapSubLine.Free;
FMarkupInfoWrapIndent.Free;
FMarkupInfoWrapEol.Free;
end; end;
procedure TLazSynEditLineWrapPlugin.WrapAll; procedure TLazSynEditLineWrapPlugin.WrapAll;