From dfadb86949866db75261b8a04521c8ba032635a3 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 21 Jan 2025 23:15:10 +0100 Subject: [PATCH] SynEdit: Wrapped-View, introduced MinWrapWidth --- components/synedit/syneditwrappedview.pp | 25 +++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/components/synedit/syneditwrappedview.pp b/components/synedit/syneditwrappedview.pp index fd46d4c28b..dfa504fedb 100644 --- a/components/synedit/syneditwrappedview.pp +++ b/components/synedit/syneditwrappedview.pp @@ -195,10 +195,14 @@ type TLazSynEditLineWrapPlugin = class(TLazSynEditPlugin) private + FCurrentWrapColumn: Integer; FCaretWrapPos: TLazSynEditWrapCaretPos; + FMinWrapWidth: Integer; procedure DoLinesChanged(Sender: TObject); procedure DoWidthChanged(Sender: TObject; Changes: TSynStatusChanges); function GetWrapColumn: Integer; + + procedure SetMinWrapWidth(AValue: Integer); public FLineMapView: TSynEditLineMappingView; function CreatePageMapNode(AMapTree: TSynLineMapAVLTree @@ -230,6 +234,7 @@ public published property CaretWrapPos: TLazSynEditWrapCaretPos read FCaretWrapPos write FCaretWrapPos; + property MinWrapWidth: Integer read FMinWrapWidth write SetMinWrapWidth; end; implementation @@ -1559,14 +1564,31 @@ end; procedure TLazSynEditLineWrapPlugin.DoWidthChanged(Sender: TObject; Changes: TSynStatusChanges); +var + w: Integer; begin - FLineMapView.KnownLengthOfLongestLine := WrapColumn; + w := WrapColumn; + if FCurrentWrapColumn = w then + exit; + FCurrentWrapColumn := w; + FLineMapView.KnownLengthOfLongestLine := w; FLineMapView.InvalidateLines(0, FLineMapView.NextLines.Count); end; function TLazSynEditLineWrapPlugin.GetWrapColumn: Integer; begin Result := TSynEdit(Editor).CharsInWindow - 1; + if Result < FMinWrapWidth then + Result := FMinWrapWidth; +end; + +procedure TLazSynEditLineWrapPlugin.SetMinWrapWidth(AValue: Integer); +begin + if AValue < 1 then + AValue := 1; + if FMinWrapWidth = AValue then Exit; + FMinWrapWidth := AValue; + DoWidthChanged(nil, [scCharsInWindow]); end; function TLazSynEditLineWrapPlugin.CreatePageMapNode(AMapTree: TSynLineMapAVLTree): TSynEditLineMapPage; @@ -1829,6 +1851,7 @@ begin FLineMapView.WrapInfoForViewedXYProc := @GetWrapInfoForViewedXY; FLineMapView.AddLinesChangedHandler(@DoLinesChanged); TSynEdit(Editor).RegisterStatusChangedHandler(@DoWidthChanged, [scCharsInWindow]); + FMinWrapWidth := 1; FLineMapView.KnownLengthOfLongestLine := WrapColumn; WrapAll; end;