@@ -265,7 +265,7 @@ public void RegisterResultsUpdatedEvent()
265265
266266 if ( token . IsCancellationRequested ) return ;
267267
268- if ( ! _resultsUpdateChannelWriter . TryWrite ( new ResultsForUpdate ( resultsCopy , pair . Metadata , e . Query ,
268+ if ( ! _resultsUpdateChannelWriter . TryWrite ( new ResultsForUpdate ( resultsCopy , pair . Metadata , e . Query ,
269269 token ) ) )
270270 {
271271 App . API . LogError ( ClassName , "Unable to add item to Result Update Queue" ) ;
@@ -791,7 +791,7 @@ private ResultsViewModel SelectedResults
791791
792792 public Visibility ProgressBarVisibility { get ; set ; }
793793 public Visibility MainWindowVisibility { get ; set ; }
794-
794+
795795 // This is to be used for determining the visibility status of the main window instead of MainWindowVisibility
796796 // because it is more accurate and reliable representation than using Visibility as a condition check
797797 public bool MainWindowVisibilityStatus { get ; set ; } = true ;
@@ -1068,7 +1068,7 @@ private bool CanExternalPreviewSelectedResult(out string path)
10681068 path = QueryResultsPreviewed ( ) ? Results . SelectedItem ? . Result ? . Preview . FilePath : string . Empty ;
10691069 return ! string . IsNullOrEmpty ( path ) ;
10701070 }
1071-
1071+
10721072 private bool QueryResultsPreviewed ( )
10731073 {
10741074 var previewed = PreviewSelectedItem == Results . SelectedItem ;
@@ -1278,8 +1278,6 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
12781278 // Update the query's IsReQuery property to true if this is a re-query
12791279 query . IsReQuery = isReQuery ;
12801280
1281-
1282-
12831281 ICollection < PluginPair > plugins = Array . Empty < PluginPair > ( ) ;
12841282 if ( currentIsHomeQuery )
12851283 {
@@ -1310,8 +1308,7 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
13101308 }
13111309 }
13121310
1313- var validPluginNames = plugins . Select ( x => $ "<{ x . Metadata . Name } >") ;
1314- App . API . LogDebug ( ClassName , $ "Valid <{ plugins . Count } > plugins: { string . Join ( " " , validPluginNames ) } ") ;
1311+ App . API . LogDebug ( ClassName , $ "Valid <{ plugins . Count } > plugins: { string . Join ( " " , plugins . Select ( x => $ "<{ x . Metadata . Name } >") ) } ") ;
13151312
13161313 // Do not wait for performance improvement
13171314 /*if (string.IsNullOrEmpty(query.ActionKeyword))
@@ -1339,6 +1336,12 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
13391336 Task [ ] tasks ;
13401337 if ( currentIsHomeQuery )
13411338 {
1339+ if ( ShouldClearExistingResultsForNonQuery ( plugins ) )
1340+ {
1341+ Results . Clear ( ) ;
1342+ App . API . LogDebug ( ClassName , $ "Existing results are cleared for non-query") ;
1343+ }
1344+
13421345 tasks = plugins . Select ( plugin => plugin . Metadata . HomeDisabled switch
13431346 {
13441347 false => QueryTaskAsync ( plugin , currentCancellationToken ) ,
@@ -1430,7 +1433,7 @@ await PluginManager.QueryHomeForPluginAsync(plugin, query, token) :
14301433 App . API . LogDebug ( ClassName , $ "Update results for plugin <{ plugin . Metadata . Name } >") ;
14311434
14321435 // Indicate if to clear existing results so to show only ones from plugins with action keywords
1433- var shouldClearExistingResults = ShouldClearExistingResults ( query , currentIsHomeQuery ) ;
1436+ var shouldClearExistingResults = ShouldClearExistingResultsForQuery ( query , currentIsHomeQuery ) ;
14341437 _lastQuery = query ;
14351438 _previousIsHomeQuery = currentIsHomeQuery ;
14361439
@@ -1452,8 +1455,13 @@ void QueryHistoryTask(CancellationToken token)
14521455
14531456 App . API . LogDebug ( ClassName , $ "Update results for history") ;
14541457
1458+ // Indicate if to clear existing results so to show only ones from plugins with action keywords
1459+ var shouldClearExistingResults = ShouldClearExistingResultsForQuery ( query , currentIsHomeQuery ) ;
1460+ _lastQuery = query ;
1461+ _previousIsHomeQuery = currentIsHomeQuery ;
1462+
14551463 if ( ! _resultsUpdateChannelWriter . TryWrite ( new ResultsForUpdate ( results , _historyMetadata , query ,
1456- token ) ) )
1464+ token , reSelect , shouldClearExistingResults ) ) )
14571465 {
14581466 App . API . LogError ( ClassName , "Unable to add item to Result Update Queue" ) ;
14591467 }
@@ -1539,7 +1547,9 @@ private async Task BuildQueryAsync(IEnumerable<BaseBuiltinShortcutModel> builtIn
15391547
15401548 /// <summary>
15411549 /// Determines whether the existing search results should be cleared based on the current query and the previous query type.
1542- /// This is needed because of the design that treats plugins with action keywords and global action keywords separately. Results are gathered
1550+ /// This is used to indicate to QueryTaskAsync or QueryHistoryTask whether to clear results. If both QueryTaskAsync and QueryHistoryTask
1551+ /// are not called then use ShouldClearExistingResultsForNonQuery instead.
1552+ /// This method needed because of the design that treats plugins with action keywords and global action keywords separately. Results are gathered
15431553 /// either from plugins with matching action keywords or global action keyword, but not both. So when the current results are from plugins
15441554 /// with a matching action keyword and a new result set comes from a new query with the global action keyword, the existing results need to be cleared,
15451555 /// and vice versa. The same applies to home page query results.
@@ -1550,19 +1560,39 @@ private async Task BuildQueryAsync(IEnumerable<BaseBuiltinShortcutModel> builtIn
15501560 /// <param name="query">The current query.</param>
15511561 /// <param name="currentIsHomeQuery">A flag indicating if the current query is a home query.</param>
15521562 /// <returns>True if the existing results should be cleared, false otherwise.</returns>
1553- private bool ShouldClearExistingResults ( Query query , bool currentIsHomeQuery )
1563+ private bool ShouldClearExistingResultsForQuery ( Query query , bool currentIsHomeQuery )
15541564 {
15551565 // If previous or current results are from home query, we need to clear them
15561566 if ( _previousIsHomeQuery || currentIsHomeQuery )
15571567 {
1558- App . API . LogDebug ( ClassName , $ "Cleared old results") ;
1568+ App . API . LogDebug ( ClassName , $ "Existing results should be cleared for query ") ;
15591569 return true ;
15601570 }
15611571
15621572 // If the last and current query are not home query type, we need to check the action keyword
15631573 if ( _lastQuery ? . ActionKeyword != query ? . ActionKeyword )
15641574 {
1565- App . API . LogDebug ( ClassName , $ "Cleared old results") ;
1575+ App . API . LogDebug ( ClassName , $ "Existing results should be cleared for query") ;
1576+ return true ;
1577+ }
1578+
1579+ return false ;
1580+ }
1581+
1582+ /// <summary>
1583+ /// Determines whether existing results should be cleared for non-query calls.
1584+ /// A non-query call is where QueryTaskAsync and QueryHistoryTask methods are both not called.
1585+ /// QueryTaskAsync and QueryHistoryTask both handle result updating (clearing if required) so directly calling
1586+ /// Results.Clear() is not required. However when both are not called, we need to directly clear results and this
1587+ /// method determines on the condition when clear results should happen.
1588+ /// </summary>
1589+ /// <param name="plugins">The collection of plugins to check.</param>
1590+ /// <returns>True if existing results should be cleared, false otherwise.</returns>
1591+ private bool ShouldClearExistingResultsForNonQuery ( ICollection < PluginPair > plugins )
1592+ {
1593+ if ( ! Settings . ShowHistoryResultsForHomePage && ( plugins . Count == 0 || plugins . All ( x => x . Metadata . HomeDisabled == true ) ) )
1594+ {
1595+ App . API . LogDebug ( ClassName , $ "Existing results should be cleared for non-query") ;
15661596 return true ;
15671597 }
15681598
0 commit comments