Skip to content

Commit

Permalink
Merge branch 'search-fix-simple-theme' of https://github.com/Avalonia…
Browse files Browse the repository at this point in the history
…UI/AvaloniaEdit into search-fix-simple-theme
  • Loading branch information
danipen committed Mar 6, 2023
2 parents 7832129 + a3da472 commit 3672c68
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions src/AvaloniaEdit/Search/SearchPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -278,15 +286,7 @@ private void ValidateSearchText()
if (_searchTextBox == null)
return;

try
{
UpdateSearch();
_validationError = null;
}
catch (SearchPatternException ex)
{
_validationError = ex.Message;
}
UpdateSearch();
}

/// <summary>
Expand Down Expand Up @@ -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))
{
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3672c68

Please sign in to comment.