From 62e1252ac4a01aff2f2244182092887373282f87 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 2 May 2025 14:37:10 +0800 Subject: [PATCH 1/4] Use BackToQueryResults for code quality --- Flow.Launcher/ViewModel/MainViewModel.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 2f1ed0f5103..2526adef83b 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1170,7 +1170,7 @@ private void QueryHistory() OriginQuery = new Query { RawQuery = h.Query }, Action = _ => { - SelectedResults = Results; + App.API.BackToQueryResults(); App.API.ChangeQuery(h.Query); return false; } @@ -1600,10 +1600,7 @@ public async void Hide() await CloseExternalPreviewAsync(); } - if (!QueryResultsSelected()) - { - SelectedResults = Results; - } + BackToQueryResults(); switch (Settings.LastQueryMode) { 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 2/4] 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 2526adef83b..f0513c7d9ab 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -34,6 +34,7 @@ public partial class MainViewModel : BaseModel, ISavable, IDisposable 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 @@ private ResultsViewModel SelectedResults 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 @@ private bool QueryResultsPreviewed() 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); From f935d5f078dc414b72375cfa5d01e28e75033a24 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 2 May 2025 15:06:20 +0800 Subject: [PATCH 3/4] Improve code comments --- Flow.Launcher/ViewModel/MainViewModel.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index f0513c7d9ab..607b70fd23a 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1432,10 +1432,10 @@ private async Task BuildQueryAsync(IEnumerable builtIn } } + // Show expanded builtin shortcuts if (queryChanged) { - // show expanded builtin shortcuts - // use private field to avoid infinite recursion + // Use private field to avoid infinite recursion _queryText = queryBuilderTmp.ToString(); OnPropertyChanged(nameof(QueryText)); } From 247272c9aa7a986395a14beab3d6a5b2e22e4b75 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 2 May 2025 15:21:17 +0800 Subject: [PATCH 4/4] Do not query when expanding builtin shortcuts --- Flow.Launcher/ViewModel/MainViewModel.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 607b70fd23a..c505c32a3c9 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1437,6 +1437,9 @@ private async Task BuildQueryAsync(IEnumerable builtIn { // Use private field to avoid infinite recursion _queryText = queryBuilderTmp.ToString(); + // 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)); } }