Skip to content

Commit

Permalink
Expand on find. Already did expand on 'activate memo and move caret' …
Browse files Browse the repository at this point in the history
…before for stuff like errors. Wondering if there's more.
  • Loading branch information
martijnlaan committed Jun 16, 2024
1 parent c0ec9d7 commit e41b89e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
22 changes: 22 additions & 0 deletions Components/ScintEdit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ TScintEdit = class(TWinControl)
procedure DeleteMarker(const Line: Integer; const Marker: TScintMarkerNumber);
procedure DPIChanged(const Message: TMessage);
procedure EndUndoAction;
procedure EnsureLineVisible(const Line: Integer);
function FindRawText(const StartPos, EndPos: Integer; const S: TScintRawString;
const Options: TScintFindOptions; out MatchRange: TScintRange): Boolean;
function FindText(const StartPos, EndPos: Integer; const S: String;
Expand Down Expand Up @@ -272,6 +273,7 @@ TScintEdit = class(TWinControl)
procedure ScrollCaretIntoView;
procedure SelectAll;
procedure SelectAllOccurrences(const Options: TScintFindOptions);
procedure SelectAndEnsureVisible(const Range: TScintRange);
procedure SelectNextOccurrence(const Options: TScintFindOptions);
function SelEmpty: Boolean;
function SelNotEmpty(out Sel: TScintRange): Boolean;
Expand Down Expand Up @@ -754,6 +756,11 @@ procedure TScintEdit.EndUndoAction;
Call(SCI_ENDUNDOACTION, 0, 0);
end;

procedure TScintEdit.EnsureLineVisible(const Line: Integer);
begin
Call(SCI_ENSUREVISIBLE, Line, 0);
end;

class function TScintEdit.GetErrorException(const S: String): EScintEditError;
begin
Result := EScintEditError.Create('TScintEdit error: ' + S);
Expand Down Expand Up @@ -1314,6 +1321,21 @@ procedure TScintEdit.SelectAllOccurrences(const Options: TScintFindOptions);
Call(SCI_MULTIPLESELECTADDEACH, 0, 0);
end;

procedure TScintEdit.SelectAndEnsureVisible(const Range: TScintRange);
begin
CheckPosRange(Range.StartPos, Range.EndPos);

{ If the range is in a collapsed section, expand it }
var StartLine := GetLineFromPosition(Range.StartPos);
var EndLine := GetLineFromPosition(Range.EndPos);
EnsureLineVisible(StartLine);
if EndLine <> StartLine then
EnsureLineVisible(EndLine);

{ Select }
Selection := Range;
end;

procedure TScintEdit.SelectNextOccurrence(const Options: TScintFindOptions);
begin
Call(SCI_TARGETWHOLEDOCUMENT, 0, 0);
Expand Down
7 changes: 4 additions & 3 deletions Projects/Src/CompForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3132,7 +3132,7 @@ procedure TCompileForm.FindNext;
end;
if FActiveMemo.FindText(StartPos, EndPos, FLastFindText,
FindOptionsToSearchOptions(FLastFindOptions), Range) then
FActiveMemo.Selection := Range
FActiveMemo.SelectAndEnsureVisible(Range)
else
MsgBoxFmt('Cannot find "%s"', [FLastFindText], SCompilerFormCaption,
mbInformation, MB_OK);
Expand Down Expand Up @@ -3855,7 +3855,8 @@ procedure TCompileForm.MoveCaretAndActivateMemo(AMemo: TCompScintEdit; const Lin
else
Pos := AMemo.CaretPosition; { Not actually moving caret - it's already were we want it}

AMemo.Call(SCI_ENSUREVISIBLE, AMemo.GetLineFromPosition(Pos), 0);
{ If the line is in a collapsed section, expand it }
AMemo.EnsureLineVisible(AMemo.GetLineFromPosition(Pos));

{ If the line isn't in view, scroll so that it's in the center }
if not AMemo.IsPositionInViewVertically(Pos) then
Expand Down Expand Up @@ -6429,7 +6430,7 @@ procedure TCompileForm.FindResultsListDblClick(Sender: TObject);
for Memo in FFileMemos do begin
if Memo.Used and (PathCompare(Memo.Filename, FindResult.Filename) = 0) then begin
MoveCaretAndActivateMemo(Memo, FindResult.Line, True);
Memo.Selection := FindResult.Range;
Memo.SelectAndEnsureVisible(FindResult.Range);
ActiveControl := Memo;
Exit;
end;
Expand Down

0 comments on commit e41b89e

Please sign in to comment.