@@ -3281,72 +3281,77 @@ procedure TCompileForm.UpdateOccurrenceIndicators(const AMemo: TCompScintEdit);
3281
3281
3282
3282
procedure FindTextAndAddRanges (const AMemo: TCompScintEdit;
3283
3283
const TextToFind: TScintRawString; const Options: TScintFindOptions;
3284
- const SelNotEmpty: Boolean; const Selection: TScintRange;
3285
- const ARangeList: TScintRangeList);
3284
+ const SelectionRanges, IndicatorRanges: TScintRangeList);
3286
3285
begin
3287
3286
if ScintRawStringIsBlank(TextToFind) then
3288
3287
Exit;
3289
3288
3290
3289
var StartPos := 0 ;
3291
3290
var EndPos := AMemo.RawTextLength;
3292
- var Range : TScintRange;
3291
+ var FoundRange : TScintRange;
3293
3292
3294
3293
while (StartPos < EndPos) and
3295
- AMemo.FindRawText(StartPos, EndPos, TextToFind, Options, Range ) do begin
3296
- StartPos := Range .EndPos;
3294
+ AMemo.FindRawText(StartPos, EndPos, TextToFind, Options, FoundRange ) do begin
3295
+ StartPos := FoundRange .EndPos;
3297
3296
3298
3297
{ Don't add indicators on lines which have a line marker }
3299
- var Line := AMemo.GetLineFromPosition(Range .StartPos);
3298
+ var Line := AMemo.GetLineFromPosition(FoundRange .StartPos);
3300
3299
var Markers := AMemo.GetMarkers(Line);
3301
3300
if Markers * [mmLineError, mmLineBreakpointBad, mmLineStep] <> [] then
3302
3301
Continue;
3303
3302
3304
- { Add indicator while making sure it does not overlap the regular selection
3305
- styling (only looks at main selection and not any additional selections
3306
- atm - so if you ctrl+double click a word and then do the same on an
3307
- occurrence somewhere else the additional selection becomes hidden by the
3308
- indicator except for the very top and bottom (due to use of
3309
- INDIC_STRAIGHTBOX instead of INDIC_FULLBOX) }
3310
- if SelNotEmpty and Range.Overlaps(Selection) then begin
3311
- if Range.StartPos < Selection.StartPos then
3312
- ARangeList.Add(TScintRange.Create(Range.StartPos, Selection.StartPos));
3313
- if Range.EndPos > Selection.EndPos then
3314
- ARangeList.Add(TScintRange.Create(Selection.EndPos, Range.EndPos));
3303
+ { Add indicator while making sure it does not overlap any regular selection
3304
+ styling for either the main selection or any additional selection. Does
3305
+ not account for an indicator overlapping more than 1 selection. }
3306
+ var OverlappingSelection: TScintRange;
3307
+ if SelectionRanges.Overlaps(FoundRange, OverlappingSelection) then begin
3308
+ if FoundRange.StartPos < OverlappingSelection.StartPos then
3309
+ IndicatorRanges.Add(TScintRange.Create(FoundRange.StartPos, OverlappingSelection.StartPos));
3310
+ if FoundRange.EndPos > OverlappingSelection.EndPos then
3311
+ IndicatorRanges.Add(TScintRange.Create(OverlappingSelection.EndPos, FoundRange.EndPos));
3315
3312
end else
3316
- ARangeList .Add(TScintRange.Create(Range.StartPos, Range.EndPos) );
3313
+ IndicatorRanges .Add(FoundRange );
3317
3314
end ;
3318
3315
end ;
3319
3316
3320
3317
begin
3321
3318
{ Add occurrence indicators for the word at cursor if there's any and the
3322
- selection is within this word. On top of those add occurrence indicators for
3323
- the selected text if there's any. Don't do anything of the selection is not
3324
- single line. All of these things are just like VSCode. }
3319
+ main selection is within this word. On top of those add occurrence indicators
3320
+ for the main selected text if there's any. Don't do anything if the main
3321
+ selection is not single line. All of these things are just like VSCode. }
3325
3322
3326
- var Selection : TScintRange;
3327
- var SelNotEmpty := AMemo.SelNotEmpty(Selection );
3328
- var SelSingleLine := AMemo.GetLineFromPosition(Selection .StartPos) =
3329
- AMemo.GetLineFromPosition(Selection .EndPos);
3323
+ var MainSelection : TScintRange;
3324
+ var MainSelNotEmpty := AMemo.SelNotEmpty(MainSelection );
3325
+ var MainSelSingleLine := AMemo.GetLineFromPosition(MainSelection .StartPos) =
3326
+ AMemo.GetLineFromPosition(MainSelection .EndPos);
3330
3327
3331
- var RangeList := TScintRangeList.Create;
3328
+ var IndicatorRanges: TScintRangeList := nil ;
3329
+ var SelectionRanges: TScintRangeList := nil ;
3332
3330
try
3333
- if FOptions.HighlightWordAtCursorOccurrences and (AMemo.CaretVirtualSpace = 0 ) and SelSingleLine then begin
3331
+ IndicatorRanges := TScintRangeList.Create;
3332
+ SelectionRanges := TScintRangeList.Create;
3333
+
3334
+ if FOptions.HighlightWordAtCursorOccurrences and (AMemo.CaretVirtualSpace = 0 ) and MainSelSingleLine then begin
3334
3335
var Word := AMemo.WordAtCursorRange;
3335
- if (Word.StartPos <> Word.EndPos) and Selection .Within(Word) then begin
3336
+ if (Word.StartPos <> Word.EndPos) and MainSelection .Within(Word) then begin
3336
3337
var TextToIndicate := AMemo.GetRawTextRange(Word.StartPos, Word.EndPos);
3337
- FindTextAndAddRanges(AMemo, TextToIndicate, GetWordOccurrenceFindOptions, SelNotEmpty, Selection, RangeList);
3338
+ AMemo.GetSelections(SelectionRanges); { Gets any additional selections as well }
3339
+ FindTextAndAddRanges(AMemo, TextToIndicate, GetWordOccurrenceFindOptions, SelectionRanges, IndicatorRanges);
3338
3340
end ;
3339
3341
end ;
3340
- AMemo.UpdateIndicators(RangeList , inWordAtCursorOccurrence);
3342
+ AMemo.UpdateIndicators(IndicatorRanges , inWordAtCursorOccurrence);
3341
3343
3342
- RangeList .Clear;
3343
- if FOptions.HighlightSelTextOccurrences and SelNotEmpty and SelSingleLine then begin
3344
+ IndicatorRanges .Clear;
3345
+ if FOptions.HighlightSelTextOccurrences and MainSelNotEmpty and MainSelSingleLine then begin
3344
3346
var TextToIndicate := AMemo.RawSelText;
3345
- FindTextAndAddRanges(AMemo, TextToIndicate, GetSelTextOccurrenceFindOptions, SelNotEmpty, Selection, RangeList);
3347
+ if SelectionRanges.Count = 0 then { If 0 then we didn't already call GetSelections above}
3348
+ AMemo.GetSelections(SelectionRanges);
3349
+ FindTextAndAddRanges(AMemo, TextToIndicate, GetSelTextOccurrenceFindOptions,SelectionRanges, IndicatorRanges);
3346
3350
end ;
3347
- AMemo.UpdateIndicators(RangeList , inSelTextOccurrence);
3351
+ AMemo.UpdateIndicators(IndicatorRanges , inSelTextOccurrence);
3348
3352
finally
3349
- RangeList.Free;
3353
+ SelectionRanges.Free;
3354
+ IndicatorRanges.Free;
3350
3355
end ;
3351
3356
end ;
3352
3357
0 commit comments