SynEdit: WrappedView, keep topline when rewrapping

This commit is contained in:
Martin 2025-02-21 16:56:18 +01:00
parent 507e0d9ceb
commit aac3d8d8db
2 changed files with 13 additions and 3 deletions

View File

@ -914,7 +914,6 @@ type
procedure SetSelEnd(const Value: integer); override;
procedure SetSelStart(const Value: integer); override;
property TextView : TSynEditStringsLinked read FTheLinesView;
property TopView: Integer read GetTopView write SetTopView; // TopLine converted into Visible(View) lines
function PasteFromClipboardEx(ClipHelper: TSynClipboardStream; AForceColumnMode: Boolean = False): Boolean;
function FindNextUnfoldedLine(iLine: integer; Down: boolean): Integer;
// Todo: Reduce the argument list of Creategutter
@ -931,6 +930,7 @@ type
procedure EndUpdate; override;
public
property TopView: Integer read GetTopView write SetTopView; // TopLine converted into Visible(View) lines
// Caret
function CaretXPix: Integer; override;
function CaretYPix: Integer; override;

View File

@ -2405,9 +2405,15 @@ end;
procedure TLazSynEditLineWrapPlugin.ValidateAll;
var
AMaxWidth, i, w: Integer;
LowLine, HighLine: TLineIdx;
LowLine, HighLine, TopViewIdx, TopLineIdx, TopSubLine: TLineIdx;
tsub: TLineRange;
begin
if not FLineMapView.Tree.NeedsValidation then exit;
if not FLineMapView.Tree.NeedsValidation then exit;
TopViewIdx := ToIdx(TSynEdit(Editor).TopView);
TopLineIdx := ViewedTextBuffer.DisplayView.ViewToTextIndexEx(TopViewIdx, tsub);
TopSubLine := TopViewIdx - tsub.Top;
AMaxWidth := WrapColumn;
while FLineMapView.Tree.NextBlockForValidation(LowLine, HighLine) do begin
@ -2418,6 +2424,10 @@ if not FLineMapView.Tree.NeedsValidation then exit;
end;
FLineMapView.Tree.EndValidate;
FLineMapView.SendNotification(senrLineMappingChanged, FLineMapView, 0, 0);
tsub := ViewedTextBuffer.DisplayView.TextToViewIndex(TopLineIdx);
TSynEdit(Editor).Topview := ToPos(tsub.Top + Min(TopSubLine, tsub.Bottom - tsub.Top));
TSynEdit(Editor).Invalidate;
end;