Skip to content

Commit

Permalink
Revert "Ignore previous: we do know whether it's the 'first' SelectNe…
Browse files Browse the repository at this point in the history
…xt or not."`

Doesn't work: it selects two occurrences on the first shortcut use.
  • Loading branch information
martijnlaan committed Jun 14, 2024
1 parent 4fab5a5 commit 0ec62b9
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions Projects/Src/CompForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ TCompileForm = class(TUIStateForm)
FBackNavButtonShortCut, FForwardNavButtonShortCut: TShortCut;
FIgnoreTabSetClick: Boolean;
FSelectNextOccurrenceShortCut, FSelectAllOccurrencesShortCut: TShortCut;
FSelectNextOccurrenceOptions: TScintFindOptions;
function AnyMemoHasBreakPoint: Boolean;
class procedure AppOnException(Sender: TObject; E: Exception);
procedure AppOnActivate(Sender: TObject);
Expand Down Expand Up @@ -524,7 +523,6 @@ TCompileForm = class(TUIStateForm)
procedure ResetAllMemosLineState;
procedure StartProcess;
function SaveFile(const AMemo: TCompScintFileEdit; const SaveAs: Boolean): Boolean;
function SelectAllOrNextOccurrencesStart: TScintFindOptions;
procedure SetErrorLine(const AMemo: TCompScintFileEdit; const ALine: Integer);
procedure SetStatusPanelVisible(const AVisible: Boolean);
procedure SetStepLine(const AMemo: TCompScintFileEdit; ALine: Integer);
Expand Down Expand Up @@ -940,10 +938,6 @@ constructor TCompileForm.Create(AOwner: TComponent);
FMenuBitmapsSize.cx := 0;
FMenuBitmapsSize.cy := 0;

{ Only used if a multi selection is started manually with a non-empty main
selection before FSelectNextOccurrenceShortCut is used }
FSelectNextOccurrenceOptions := GetSelTextOccurrenceFindOptions;

if CommandLineCompile then begin
ReadSignTools(FSignTools);
PostMessage(Handle, WM_StartCommandLineCompile, 0, 0)
Expand Down Expand Up @@ -2520,33 +2514,26 @@ procedure TCompileForm.ESelectAllClick(Sender: TObject);
FActiveMemo.SelectAll;
end;

function TCompileForm.SelectAllOrNextOccurrencesStart: TScintFindOptions;
procedure TCompileForm.ESelectAllOccurrencesClick(Sender: TObject);
begin
Result := GetSelTextOccurrenceFindOptions;
var Options := GetSelTextOccurrenceFindOptions;
if FActiveMemo.SelEmpty then begin
var Range := FActiveMemo.WordAtCursorRange;
if Range.StartPos <> Range.EndPos then begin
FActiveMemo.SetSingleSelection(Range.EndPos, Range.StartPos);
Result := GetWordOccurrenceFindOptions;
Options := GetWordOccurrenceFindOptions;
end;
end;
end;

procedure TCompileForm.ESelectAllOccurrencesClick(Sender: TObject);
begin
var Options := SelectAllOrNextOccurrencesStart;
FActiveMemo.SelectAllOccurrences(Options);
end;

procedure TCompileForm.ESelectNextOccurrenceClick(Sender: TObject);
begin
{ This is the 'first' SelectNext if there are no additional selections yet or
if the main selection is empty. The first SelectNext determines the find
options to be used for the next SelectNext. This is like VSCode as also
consistent with SelectAll and occurrence highlighting. }
if (FActiveMemo.SelectionCount = 1) or FActiveMemo.SelEmpty then
FSelectNextOccurrenceOptions := SelectAllOrNextOccurrencesStart;
FActiveMemo.SelectNextOccurrence(FSelectNextOccurrenceOptions);
{ Currently this always uses GetWordOccurrenceFindOptions but ideally it would
know whether this is the 'first' SelectNext or not. Then, if first it would
do what SelectAll does to choose a FindOptions. And if next it would reuse
that. This is what VSCode does. }
FActiveMemo.SelectNextOccurrence(GetWordOccurrenceFindOptions);
end;

procedure TCompileForm.ECompleteWordClick(Sender: TObject);
Expand Down

0 comments on commit 0ec62b9

Please sign in to comment.