@@ -34,6 +34,7 @@ public partial class MainViewModel : BaseModel, ISavable, IDisposable
3434 private bool _isQueryRunning ;
3535 private Query _lastQuery ;
3636 private string _queryTextBeforeLeaveResults ;
37+ private string _ignoredQueryText = null ;
3738
3839 private readonly FlowLauncherJsonStorage < History > _historyItemsStorage ;
3940 private readonly FlowLauncherJsonStorage < UserSelectedRecord > _userSelectedRecordStorage ;
@@ -730,6 +731,9 @@ private ResultsViewModel SelectedResults
730731 if ( isReturningFromContextMenu )
731732 {
732733 _queryText = _queryTextBeforeLeaveResults ;
734+ // When executing OnPropertyChanged, QueryTextBox_TextChanged1 and Query will be called
735+ // So we need to ignore it so that we will not call Query again
736+ _ignoredQueryText = _queryText ;
733737 OnPropertyChanged ( nameof ( QueryText ) ) ;
734738 QueryTextCursorMovedToEnd = true ;
735739 }
@@ -1076,6 +1080,20 @@ private bool QueryResultsPreviewed()
10761080
10771081 public void Query ( bool searchDelay , bool isReQuery = false )
10781082 {
1083+ if ( _ignoredQueryText != null )
1084+ {
1085+ if ( _ignoredQueryText == QueryText )
1086+ {
1087+ _ignoredQueryText = null ;
1088+ return ;
1089+ }
1090+ else
1091+ {
1092+ // If _ignoredQueryText does not match current QueryText, we should still execute Query
1093+ _ignoredQueryText = null ;
1094+ }
1095+ }
1096+
10791097 if ( QueryResultsSelected ( ) )
10801098 {
10811099 _ = QueryResultsAsync ( searchDelay , isReQuery ) ;
@@ -1170,7 +1188,7 @@ private void QueryHistory()
11701188 OriginQuery = new Query { RawQuery = h . Query } ,
11711189 Action = _ =>
11721190 {
1173- SelectedResults = Results ;
1191+ App . API . BackToQueryResults ( ) ;
11741192 App . API . ChangeQuery ( h . Query ) ;
11751193 return false ;
11761194 }
@@ -1414,11 +1432,14 @@ private async Task BuildQueryAsync(IEnumerable<BaseBuiltinShortcutModel> builtIn
14141432 }
14151433 }
14161434
1435+ // Show expanded builtin shortcuts
14171436 if ( queryChanged )
14181437 {
1419- // show expanded builtin shortcuts
1420- // use private field to avoid infinite recursion
1438+ // Use private field to avoid infinite recursion
14211439 _queryText = queryBuilderTmp . ToString ( ) ;
1440+ // When executing OnPropertyChanged, QueryTextBox_TextChanged1 and Query will be called
1441+ // So we need to ignore it so that we will not call Query again
1442+ _ignoredQueryText = _queryText ;
14221443 OnPropertyChanged ( nameof ( QueryText ) ) ;
14231444 }
14241445 }
@@ -1600,10 +1621,7 @@ public async void Hide()
16001621 await CloseExternalPreviewAsync ( ) ;
16011622 }
16021623
1603- if ( ! QueryResultsSelected ( ) )
1604- {
1605- SelectedResults = Results ;
1606- }
1624+ BackToQueryResults ( ) ;
16071625
16081626 switch ( Settings . LastQueryMode )
16091627 {
0 commit comments