فهرست منبع

Fix ESelectNextOccurrence and ESelectAllOccurrences search options. Also add a comment to explain the preselect.

Martijn Laan 10 ماه پیش
والد
کامیت
292c0d9156
2فایلهای تغییر یافته به همراه7 افزوده شده و 25 حذف شده
  1. 0 12
      Projects/Src/IDE.HelperFunc.pas
  2. 7 13
      Projects/Src/IDE.MainForm.pas

+ 0 - 12
Projects/Src/IDE.HelperFunc.pas

@@ -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;
 
@@ -848,16 +846,6 @@ begin
   Result.bmiHeader.biCompression := BI_RGB;
 end;
 
-function GetWordOccurrenceFindOptions: TScintFindOptions;
-begin
-  Result := [sfoMatchCase, sfoWholeWord];
-end;
-
-function GetSelTextOccurrenceFindOptions: TScintFindOptions;
-begin
-  Result := [];
-end;
-
 var
   PreferredMemoFont: String;
 

+ 7 - 13
Projects/Src/IDE.MainForm.pas

@@ -2995,26 +2995,20 @@ end;
 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);
@@ -4027,7 +4021,7 @@ begin
       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);
@@ -4037,7 +4031,7 @@ begin
       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