IDE: SourceEditor, keep topline when changing highlighter and wordwrap on/off

This commit is contained in:
Martin 2025-03-19 17:07:40 +01:00
parent 6efa78a255
commit 4f387e226f
2 changed files with 10 additions and 2 deletions

View File

@ -5117,10 +5117,13 @@ procedure TSourceEditor.SetSyntaxHighlighterId(AHighlighterId: TIdeSyntaxHighlig
ASkipEditorOpts: boolean);
var
HlIsPas, OldHlIsPas: Boolean;
tl: TSrcSynTopLineInfo;
begin
if (AHighlighterId=fSyntaxHighlighterId)
and ((FEditor.Highlighter<>nil) = EditorOpts.UseSyntaxHighlight) then exit;
if not ASkipEditorOpts then
tl := FEditor.GetTopLineBeforeFold;
FEditor.BeginUpdate(False);
try
OldHlIsPas := FEditor.Highlighter is TSynPasSyn;
@ -5164,6 +5167,8 @@ begin
SourceEditorManager.SendEditorReconfigured(Self);
finally
FEditor.EndUpdate;
if not ASkipEditorOpts then
FEditor.RestoreTopLineAfterFold(tl);
end;
end;
@ -5216,8 +5221,10 @@ end;
function TSourceEditor.RefreshEditorSettings: Boolean;
var
SimilarEditor: TSynEdit;
tl: TSrcSynTopLineInfo;
Begin
Result:=true;
tl := FEditor.GetTopLineBeforeFold;
FEditor.BeginUpdate(False);
try
SetSyntaxHighlighterId(fSyntaxHighlighterId, True);
@ -5233,6 +5240,7 @@ Begin
UpdateIfDefNodeStates(True);
finally
FEditor.EndUpdate;
FEditor.RestoreTopLineAfterFold(tl);
end;
SourceEditorManager.SendEditorReconfigured(Self);
end;

View File

@ -311,8 +311,6 @@ type
procedure SrcSynCaretChanged(Sender: TObject);
function GetHighlighter: TSynCustomFoldHighlighter;
protected
function GetTopLineBeforeFold: TSrcSynTopLineInfo;
procedure RestoreTopLineAfterFold(AnInfo: TSrcSynTopLineInfo);
procedure DoOnStatusChange(Changes: TSynStatusChanges); override;
function CreateGutter(AOwner : TSynEditBase; ASide: TSynGutterSide;
ATextDrawer: TheTextDrawer): TSynGutter; override;
@ -324,6 +322,8 @@ type
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function TextIndexToViewPos(aTextIndex : Integer) : Integer; // Wrong name: argument is TextPos, not TextIdx
function GetTopLineBeforeFold: TSrcSynTopLineInfo;
procedure RestoreTopLineAfterFold(AnInfo: TSrcSynTopLineInfo);
property IDEGutterMarks: TIDESynGutterMarks read GetIDEGutterMarks;
property TopView;
property TextBuffer;