diff --git a/src/AvaloniaEdit/Search/SearchPanel.cs b/src/AvaloniaEdit/Search/SearchPanel.cs index b9f9e85f..e92474c3 100644 --- a/src/AvaloniaEdit/Search/SearchPanel.cs +++ b/src/AvaloniaEdit/Search/SearchPanel.cs @@ -165,11 +165,19 @@ private void UpdateSearch() // only reset as long as there are results // if no results are found, the "no matches found" message should not flicker. // if results are found by the next run, the message will be hidden inside DoSearch ... - if (_renderer.CurrentResults.Any()) - _messageView.IsVisible = false; - _strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal); - OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords)); - DoSearch(true); + try + { + if (_renderer.CurrentResults.Any()) + _messageView.IsVisible = false; + _strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal); + OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords)); + DoSearch(true); + } + catch (SearchPatternException) + { + CleanSearchResults(); + UpdateSearchLabel(); + } } static SearchPanel() @@ -278,15 +286,7 @@ private void ValidateSearchText() if (_searchTextBox == null) return; - try - { - UpdateSearch(); - _validationError = null; - } - catch (SearchPatternException ex) - { - _validationError = ex.Message; - } + UpdateSearch(); } /// @@ -366,14 +366,13 @@ public void ReplaceAll() private Panel _messageView; private TextBlock _messageViewContent; - private string _validationError; private void DoSearch(bool changeSelection) { if (IsClosed) return; - _renderer.CurrentResults.Clear(); - _currentSearchResultIndex = -1; + + CleanSearchResults(); if (!string.IsNullOrEmpty(SearchPattern)) { @@ -400,6 +399,12 @@ private void DoSearch(bool changeSelection) _textArea.TextView.InvalidateLayer(KnownLayer.Selection); } + void CleanSearchResults() + { + _renderer.CurrentResults.Clear(); + _currentSearchResultIndex = -1; + } + void UpdateSearchLabel() { if (_messageView == null || _messageViewContent == null) @@ -462,14 +467,6 @@ private void SearchLayerKeyDown(object sender, KeyEventArgs e) { FindNext(); } - if (_searchTextBox != null) - { - if (_validationError != null && _messageView != null && _messageViewContent != null) - { - _messageViewContent.Text = SR.SearchErrorText + " " + _validationError; - _messageView.IsVisible = true; - } - } break; case Key.Escape: e.Handled = true;