Skip to content

Commit

Permalink
Fix ESelectNextOccurrence and ESelectAllOccurrences search options. A…
Browse files Browse the repository at this point in the history
…lso add a comment to explain the preselect.
  • Loading branch information
martijnlaan committed Nov 14, 2024
1 parent 2d3b2f4 commit 292c0d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
12 changes: 0 additions & 12 deletions Projects/Src/IDE.HelperFunc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ function GetSourcePath(const AFilename: String): String;
function ReadScriptLines(const ALines: TStringList; const ReadFromFile: Boolean;
const ReadFromFileFilename: String; const NotReadFromFileMemo: TScintEdit): Integer;
function CreateBitmapInfo(const Width, Height, BitCount: Integer): TBitmapInfo;
function GetWordOccurrenceFindOptions: TScintFindOptions;
function GetSelTextOccurrenceFindOptions: TScintFindOptions;
function GetPreferredMemoFont: String;
function DoubleAmp(const S: String): String;

Expand Down Expand Up @@ -848,16 +846,6 @@ function CreateBitmapInfo(const Width, Height, BitCount: Integer): TBitmapInfo;
Result.bmiHeader.biCompression := BI_RGB;
end;

function GetWordOccurrenceFindOptions: TScintFindOptions;
begin
Result := [sfoMatchCase, sfoWholeWord];
end;

function GetSelTextOccurrenceFindOptions: TScintFindOptions;
begin
Result := [];
end;

var
PreferredMemoFont: String;

Expand Down
20 changes: 7 additions & 13 deletions Projects/Src/IDE.MainForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2995,26 +2995,20 @@ procedure TMainForm.ESelectAllClick(Sender: TObject);
procedure TMainForm.ESelectAllOccurrencesClick(Sender: TObject);
begin
{ Might be called even if ESelectAllOccurrences.Enabled would be False in EMenuClick }
var Options := GetSelTextOccurrenceFindOptions;
if FActiveMemo.SelEmpty then begin
{ If the selection is empty then SelectAllOccurrences will actually just select
the word at caret which is not what we want, so preselect this word ourselves }
var Range := FActiveMemo.WordAtCursorRange;
if Range.StartPos <> Range.EndPos then begin
if Range.StartPos <> Range.EndPos then
FActiveMemo.SetSingleSelection(Range.EndPos, Range.StartPos);
Options := GetWordOccurrenceFindOptions;
end;
end;
FActiveMemo.SelectAllOccurrences(Options);
FActiveMemo.SelectAllOccurrences([sfoMatchCase]);
end;

procedure TMainForm.ESelectNextOccurrenceClick(Sender: TObject);
begin
{ Might be called even if ESelectNextOccurrence.Enabled would be False in EMenuClick }

{ 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);
FActiveMemo.SelectNextOccurrence([sfoMatchCase]);
end;

procedure TMainForm.EToggleLinesCommentClick(Sender: TObject);
Expand Down Expand Up @@ -4027,7 +4021,7 @@ procedure TMainForm.UpdateOccurrenceIndicators(const AMemo: TIDEScintEdit);
if (Word.StartPos <> Word.EndPos) and MainSelection.Within(Word) then begin
var TextToIndicate := AMemo.GetRawTextRange(Word.StartPos, Word.EndPos);
AMemo.GetSelections(Selections); { Gets any additional selections as well }
FindTextAndAddRanges(AMemo, TextToIndicate, GetWordOccurrenceFindOptions, Selections, IndicatorRanges);
FindTextAndAddRanges(AMemo, TextToIndicate, [sfoMatchCase, sfoWholeWord], Selections, IndicatorRanges);
end;
end;
AMemo.UpdateIndicators(IndicatorRanges, minWordAtCursorOccurrence);
Expand All @@ -4037,7 +4031,7 @@ procedure TMainForm.UpdateOccurrenceIndicators(const AMemo: TIDEScintEdit);
var TextToIndicate := AMemo.RawMainSelText;
if Selections.Count = 0 then { If 0 then we didn't already call GetSelections above}
AMemo.GetSelections(Selections);
FindTextAndAddRanges(AMemo, TextToIndicate, GetSelTextOccurrenceFindOptions, Selections, IndicatorRanges);
FindTextAndAddRanges(AMemo, TextToIndicate, [], Selections, IndicatorRanges);
end;
AMemo.UpdateIndicators(IndicatorRanges, minSelTextOccurrence);
finally
Expand Down

0 comments on commit 292c0d9

Please sign in to comment.