public TextRange FindNext(bool viaF3, bool searchBackward, string messageIfNotFound) { if (_findForm == null) _findForm = new SearchAndReplace(); TextEditorSearcher _search = new TextEditorSearcher(); _lastSearchWasBackward = searchBackward; _search.Document = SharpText.Document; _search.LookFor = _findForm.LookFor; _search.MatchCase = _findForm.MatchCase; _search.MatchWholeWordOnly = _findForm.MatchWholeWordOnly; var caret = SharpText.ActiveTextAreaControl.Caret; if (viaF3 && _search.HasScanRegion && !caret.Offset.IsInRange(_search.BeginOffset, _search.EndOffset)) { // user moved outside of the originally selected region _search.ClearScanRegion(); } int startFrom = caret.Offset - (searchBackward ? 1 : 0); TextRange range = _search.FindNext(startFrom, searchBackward, out _lastSearchLoopedAround); if (range != null) SelectResult(range); else if (messageIfNotFound != null) MessageBox.Show(messageIfNotFound); return range; }
public SearchAndReplace() { InitializeComponent(); _search = new TextEditorSearcher(); }