@@ -36,6 +36,7 @@ public partial class MainViewModel : BaseModel, ISavable, IDisposable
3636 private bool _isQueryRunning ;
3737 private Query _lastQuery ;
3838 private string _queryTextBeforeLeaveResults ;
39+ private string _ignoredQueryText = null ;
3940
4041 private readonly FlowLauncherJsonStorage < History > _historyItemsStorage ;
4142 private readonly FlowLauncherJsonStorage < UserSelectedRecord > _userSelectedRecordStorage ;
@@ -797,6 +798,9 @@ private ResultsViewModel SelectedResults
797798 if ( isReturningFromContextMenu )
798799 {
799800 _queryText = _queryTextBeforeLeaveResults ;
801+ // When executing OnPropertyChanged, QueryTextBox_TextChanged1 and Query will be called
802+ // So we need to ignore it so that we will not call Query again
803+ _ignoredQueryText = _queryText ;
800804 OnPropertyChanged ( nameof ( QueryText ) ) ;
801805 QueryTextCursorMovedToEnd = true ;
802806 }
@@ -1143,6 +1147,20 @@ private bool QueryResultsPreviewed()
11431147
11441148 public void Query ( bool searchDelay , bool isReQuery = false )
11451149 {
1150+ if ( _ignoredQueryText != null )
1151+ {
1152+ if ( _ignoredQueryText == QueryText )
1153+ {
1154+ _ignoredQueryText = null ;
1155+ return ;
1156+ }
1157+ else
1158+ {
1159+ // If _ignoredQueryText does not match current QueryText, we should still execute Query
1160+ _ignoredQueryText = null ;
1161+ }
1162+ }
1163+
11461164 if ( QueryResultsSelected ( ) )
11471165 {
11481166 _ = QueryResultsAsync ( searchDelay , isReQuery ) ;
@@ -1237,7 +1255,7 @@ private void QueryHistory()
12371255 OriginQuery = new Query { RawQuery = h . Query } ,
12381256 Action = _ =>
12391257 {
1240- SelectedResults = Results ;
1258+ App . API . BackToQueryResults ( ) ;
12411259 App . API . ChangeQuery ( h . Query ) ;
12421260 return false ;
12431261 }
@@ -1264,12 +1282,16 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
12641282 {
12651283 _updateSource ? . Cancel ( ) ;
12661284
1285+ App . API . LogDebug ( ClassName , $ "Start query with text: <{ QueryText } >") ;
1286+
12671287 var query = await ConstructQueryAsync ( QueryText , Settings . CustomShortcuts , Settings . BuiltinShortcuts ) ;
12681288
12691289 var quickSwitch = _isQuickSwitch ; // save quick switch state
12701290
12711291 if ( query == null ) // shortcut expanded
12721292 {
1293+ App . API . LogDebug ( ClassName , $ "Clear query results") ;
1294+
12731295 // Hide and clear results again because running query may show and add some results
12741296 Results . Visibility = Visibility . Collapsed ;
12751297 Results . Clear ( ) ;
@@ -1284,6 +1306,8 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
12841306 return ;
12851307 }
12861308
1309+ App . API . LogDebug ( ClassName , $ "Start query with ActionKeyword <{ query . ActionKeyword } > and RawQuery <{ query . RawQuery } >") ;
1310+
12871311 _updateSource = new CancellationTokenSource ( ) ;
12881312
12891313 ProgressBarVisibility = Visibility . Hidden ;
@@ -1304,6 +1328,9 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
13041328
13051329 var plugins = PluginManager . ValidPluginsForQuery ( query , quickSwitch ) ;
13061330
1331+ var validPluginNames = plugins . Select ( x => $ "<{ x . Metadata . Name } >") ;
1332+ App . API . LogDebug ( ClassName , $ "Valid <{ plugins . Count } > plugins: { string . Join ( " " , validPluginNames ) } ") ;
1333+
13071334 if ( plugins . Count == 1 )
13081335 {
13091336 PluginIconPath = plugins . Single ( ) . Metadata . IcoPath ;
@@ -1372,6 +1399,8 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
13721399 // Local function
13731400 async Task QueryTaskAsync ( PluginPair plugin , CancellationToken token )
13741401 {
1402+ App . API . LogDebug ( ClassName , $ "Wait for querying plugin <{ plugin . Metadata . Name } >") ;
1403+
13751404 if ( searchDelay )
13761405 {
13771406 var searchDelayTime = plugin . Metadata . SearchDelayTime ?? Settings . SearchDelayTime ;
@@ -1411,6 +1440,8 @@ async Task QueryTaskAsync(PluginPair plugin, CancellationToken token)
14111440 }
14121441
14131442 if ( token . IsCancellationRequested ) return ;
1443+
1444+ App . API . LogDebug ( ClassName , $ "Update results for plugin <{ plugin . Metadata . Name } >") ;
14141445
14151446 if ( ! _resultsUpdateChannelWriter . TryWrite ( new ResultsForUpdate ( resultsCopy , plugin . Metadata , query ,
14161447 token , reSelect ) ) )
@@ -1445,6 +1476,8 @@ async Task QueryTaskAsync(PluginPair plugin, CancellationToken token)
14451476 }
14461477
14471478 if ( token . IsCancellationRequested ) return ;
1479+
1480+ App . API . LogDebug ( ClassName , $ "Update results for plugin <{ plugin . Metadata . Name } >") ;
14481481
14491482 if ( ! _resultsUpdateChannelWriter . TryWrite ( new ResultsForUpdate ( resultsCopy , plugin . Metadata , query ,
14501483 token , reSelect ) ) )
@@ -1520,11 +1553,14 @@ private async Task BuildQueryAsync(IEnumerable<BaseBuiltinShortcutModel> builtIn
15201553 }
15211554 }
15221555
1556+ // Show expanded builtin shortcuts
15231557 if ( queryChanged )
15241558 {
1525- // show expanded builtin shortcuts
1526- // use private field to avoid infinite recursion
1559+ // Use private field to avoid infinite recursion
15271560 _queryText = queryBuilderTmp . ToString ( ) ;
1561+ // When executing OnPropertyChanged, QueryTextBox_TextChanged1 and Query will be called
1562+ // So we need to ignore it so that we will not call Query again
1563+ _ignoredQueryText = _queryText ;
15281564 OnPropertyChanged ( nameof ( QueryText ) ) ;
15291565 }
15301566 }
@@ -1533,6 +1569,8 @@ private void RemoveOldQueryResults(Query query)
15331569 {
15341570 if ( _lastQuery ? . ActionKeyword != query ? . ActionKeyword )
15351571 {
1572+ App . API . LogDebug ( ClassName , $ "Remove old results") ;
1573+
15361574 Results . Clear ( ) ;
15371575 }
15381576 }
@@ -1899,10 +1937,7 @@ public async void Hide(bool reset = true)
18991937 await CloseExternalPreviewAsync ( ) ;
19001938 }
19011939
1902- if ( ! QueryResultsSelected ( ) )
1903- {
1904- SelectedResults = Results ;
1905- }
1940+ BackToQueryResults ( ) ;
19061941
19071942 switch ( Settings . LastQueryMode )
19081943 {
0 commit comments