diff --git a/Components/ScintEdit.pas b/Components/ScintEdit.pas index 357f11541..4fdcd054b 100644 --- a/Components/ScintEdit.pas +++ b/Components/ScintEdit.pas @@ -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; @@ -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; @@ -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); @@ -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); diff --git a/Projects/Src/CompForm.pas b/Projects/Src/CompForm.pas index dcead29f6..8b2c74bfe 100644 --- a/Projects/Src/CompForm.pas +++ b/Projects/Src/CompForm.pas @@ -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); @@ -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 @@ -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;