Skip to content

Commit

Permalink
Merge branch 'main' into extract7zippage
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnlaan committed Nov 14, 2024
2 parents aa1e83a + de57c26 commit 1dfd2f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 33 deletions.
10 changes: 5 additions & 5 deletions Components/ScintEdit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ TScintEdit = class(TWinControl)
function TestRawRegularExpression(const S: TScintRawString): Boolean;
procedure Undo;
procedure UpdateStyleAttributes;
function WordAtCursor: String;
function WordAtCursorRange: TScintRange;
function WordAtCaret: String;
function WordAtCaretRange: TScintRange;
procedure ZoomIn;
procedure ZoomOut;
property AutoCompleteActive: Boolean read GetAutoCompleteActive;
Expand Down Expand Up @@ -2483,13 +2483,13 @@ procedure TScintEdit.UpdateStyleAttributes;
Call(SCI_AUTOCSETSTYLE, 0, 0);
end;

function TScintEdit.WordAtCursor: String;
function TScintEdit.WordAtCaret: String;
begin
var Range := WordAtCursorRange;
var Range := WordAtCaretRange;
Result := GetTextRange(Range.StartPos, Range.EndPos);
end;

function TScintEdit.WordAtCursorRange: TScintRange;
function TScintEdit.WordAtCaretRange: TScintRange;
begin
var Pos := GetCaretPosition;
Result.StartPos := GetWordStartPosition(Pos, True);
Expand Down
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
26 changes: 10 additions & 16 deletions Projects/Src/IDE.MainForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ procedure TMainForm.MemoKeyDown(Sender: TObject; var Key: Word;
var HelpFile := GetHelpFile;
if Assigned(HtmlHelp) then begin
HtmlHelp(GetDesktopWindow, PChar(HelpFile), HH_DISPLAY_TOPIC, 0);
var S := FActiveMemo.WordAtCursor;
var S := FActiveMemo.WordAtCaret;
if S <> '' then begin
var KLink: THH_AKLINK;
FillChar(KLink, SizeOf(KLink), 0);
Expand Down 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
var Range := FActiveMemo.WordAtCursorRange;
if Range.StartPos <> Range.EndPos 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.WordAtCaretRange;
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 @@ -4023,11 +4017,11 @@ procedure TMainForm.UpdateOccurrenceIndicators(const AMemo: TIDEScintEdit);
Selections := TScintRangeList.Create;

if FOptions.HighlightWordAtCursorOccurrences and (AMemo.CaretVirtualSpace = 0) and MainSelSingleLine then begin
var Word := AMemo.WordAtCursorRange;
var Word := AMemo.WordAtCaretRange;
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 1dfd2f7

Please sign in to comment.