From b1197858de49abc6c4583085b6124c462f82cfd0 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 2 May 2025 14:40:18 +0800 Subject: [PATCH] Do not query when back from the context menu --- Flow.Launcher/ViewModel/MainViewModel.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 2526adef8..f0513c7d9 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -34,6 +34,7 @@ namespace Flow.Launcher.ViewModel private bool _isQueryRunning; private Query _lastQuery; private string _queryTextBeforeLeaveResults; + private string _ignoredQueryText = null; private readonly FlowLauncherJsonStorage _historyItemsStorage; private readonly FlowLauncherJsonStorage _userSelectedRecordStorage; @@ -730,6 +731,9 @@ namespace Flow.Launcher.ViewModel if (isReturningFromContextMenu) { _queryText = _queryTextBeforeLeaveResults; + // When executing OnPropertyChanged, QueryTextBox_TextChanged1 and Query will be called + // So we need to ignore it so that we will not call Query again + _ignoredQueryText = _queryText; OnPropertyChanged(nameof(QueryText)); QueryTextCursorMovedToEnd = true; } @@ -1076,6 +1080,20 @@ namespace Flow.Launcher.ViewModel public void Query(bool searchDelay, bool isReQuery = false) { + if (_ignoredQueryText != null) + { + if (_ignoredQueryText == QueryText) + { + _ignoredQueryText = null; + return; + } + else + { + // If _ignoredQueryText does not match current QueryText, we should still execute Query + _ignoredQueryText = null; + } + } + if (QueryResultsSelected()) { _ = QueryResultsAsync(searchDelay, isReQuery);