Skip to content

Commit d4a57c3

Browse files
committed
refactor: replace deprecated SynEdit selection API
Lazarus warns that SelStart/SelEnd are deprecated and very slow. Use native BlockBegin/BlockEnd and CaretXY instead.
1 parent 816a819 commit d4a57c3

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

source/main.pas

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15536,7 +15536,8 @@ function TQueryTab.LoadContents(Filepath: String; ReplaceContent: Boolean; Encod
1553615536
Memo.Text := Content
1553715537
else
1553815538
Memo.SelText := Content;
15539-
Memo.SelStart := Memo.SelEnd;
15539+
Memo.CaretXY := Memo.BlockEnd;
15540+
Memo.ClearSelection;
1554015541
Memo.Modified := False;
1554115542
MemoFilename := Filepath;
1554215543
FileEncoding := MainForm.GetEncodingName(Encoding);

source/texteditor.pas

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ TfrmTextEditor = class(TExtForm)
108108

109109
implementation
110110

111-
uses main;
111+
uses main, Types;
112112

113113
{$R *.lfm}
114114

@@ -381,13 +381,13 @@ procedure TfrmTextEditor.comboHighlighterSelect(Sender: TObject);
381381
var
382382
Highlighters: TSynHighlighterList;
383383
i: Integer;
384-
SelStart, SelLength: Integer;
384+
SelBegin, SelEnd: TPoint;
385385
begin
386386
// Code highlighter selected
387387
if not comboHighlighter.Enabled then
388388
Exit;
389-
SelStart := MemoText.SelStart;
390-
SelLength := MemoText.SelEnd - MemoText.SelStart;
389+
SelBegin := MemoText.BlockBegin;
390+
SelEnd := MemoText.BlockEnd;
391391
MemoText.Highlighter := nil;
392392
FHighlighter.Free;
393393
FHighlighter := nil;
@@ -403,17 +403,17 @@ procedure TfrmTextEditor.comboHighlighterSelect(Sender: TObject);
403403
menuFormatCodeOnce.Enabled := Assigned(FHighlighter) and (FHighlighterFormatters.IndexOf(FHighlighter.ClassName) > -1);
404404
if menuAlwaysFormatCode.Checked and menuFormatCodeOnce.Enabled then begin
405405
menuFormatCodeOnce.OnClick(Sender);
406-
SelStart := 0;
407-
SelLength := 0;
406+
SelBegin := Point(1, 1);
407+
SelEnd := SelBegin;
408408
end;
409409

410410
if Assigned(FHighlighter) then begin
411411
// Load custom highlighter settings from ini file, if exists:
412412
MemoText.Highlighter.LoadFromFile(AppSettings.DirnameHighlighters + MemoText.Highlighter.LanguageName + '.ini');
413413
end;
414414

415-
MemoText.SelStart := SelStart;
416-
MemoText.SelEnd := SelStart + SelLength;
415+
MemoText.BlockBegin := SelBegin;
416+
MemoText.BlockEnd := SelEnd;
417417
end;
418418

419419
procedure TfrmTextEditor.btnLoadTextClick(Sender: TObject);
@@ -468,15 +468,15 @@ procedure TfrmTextEditor.menuFormatCodeOnceClick(Sender: TObject);
468468
JsonParser := TJSONParser.Create(MemoText.Text, []);
469469
MemoText.Text := JsonParser.Parse.FormatJSON();
470470
JsonParser.Free;
471-
MemoText.SelStart := 0;
472-
MemoText.SelEnd := 0;
471+
MemoText.CaretXY := Point(1, 1);
472+
MemoText.ClearSelection;
473473
end
474474
else if FHighlighter is TSynSQLSyn then begin
475475
// Prefer old internal formatter here, so the user does not run into request limits
476476
frmReformatter := TfrmReformatter.Create(Self);
477477
MemoText.Text := frmReformatter.FormatSqlInternal(MemoText.Text);
478-
MemoText.SelStart := 0;
479-
MemoText.SelEnd := 0;
478+
MemoText.CaretXY := Point(1, 1);
479+
MemoText.ClearSelection;
480480
frmReformatter.Free;
481481
end
482482
else if FHighlighter is TSynXMLSyn then begin
@@ -492,8 +492,8 @@ procedure TfrmTextEditor.menuFormatCodeOnceClick(Sender: TObject);
492492
MemoText.BeginUpdate;
493493
MemoText.Text := OutStream.DataString; // show formatted XML
494494
MemoText.EndUpdate;
495-
MemoText.SelStart := 0;
496-
MemoText.SelEnd := 0;
495+
MemoText.CaretXY := Point(1, 1);
496+
MemoText.ClearSelection;
497497
finally
498498
InStream.Free;
499499
OutStream.Free;

0 commit comments

Comments
 (0)