Skip to content

Commit

Permalink
修复重复搜索没有生效的问题 (#216)
Browse files Browse the repository at this point in the history
* 修复重复搜索没有生效的问题

* 在搜索时终止之前的建议查询
  • Loading branch information
Richasy authored Jan 7, 2024
1 parent b169418 commit 6497681
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/App/Forms/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ private void OnRequestSearch(object sender, string e)
vm.InitializeCommand.Execute(default);
_ = OverlayFrame.Navigate(typeof(SearchPage), vm);
}
else
{
var page = OverlayFrame.Content as SearchPage;
page.ViewModel.SetKeyword(e);
page.ViewModel.InitializeCommand.Execute(default);
}
}

private void OnRequestShowMyMessages(object sender, EventArgs e)
Expand Down
17 changes: 10 additions & 7 deletions src/ViewModels/Components/SearchBoxViewModel/SearchBoxViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,22 @@ private void SearchBySuggest(SearchSuggest suggest)
[RelayCommand]
private void SearchByText(string text)
{
CancelSuggestion();
TryClear(AutoSuggestCollection);
QueryText = text;
AppViewModel.Instance.SearchContentCommand.Execute(text);
}

private void InitializeSuggestionCancellationTokenSource()
private void CancelSuggestion()
{
if (_suggestionCancellationTokenSource != null
&& !_suggestionCancellationTokenSource.IsCancellationRequested)
{
_suggestionCancellationTokenSource.Cancel();
_suggestionCancellationTokenSource = null;
}
_suggestionCancellationTokenSource?.Cancel();
_suggestionCancellationTokenSource?.Dispose();
_suggestionCancellationTokenSource = null;
}

private void InitializeSuggestionCancellationTokenSource()
{
CancelSuggestion();
_suggestionCancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(1));
}

Expand Down

0 comments on commit 6497681

Please sign in to comment.