@@ -265,7 +265,7 @@ public void RegisterResultsUpdatedEvent()
265
265
266
266
if ( token . IsCancellationRequested ) return ;
267
267
268
- if ( ! _resultsUpdateChannelWriter . TryWrite ( new ResultsForUpdate ( resultsCopy , pair . Metadata , e . Query ,
268
+ if ( ! _resultsUpdateChannelWriter . TryWrite ( new ResultsForUpdate ( resultsCopy , pair . Metadata , e . Query ,
269
269
token ) ) )
270
270
{
271
271
App . API . LogError ( ClassName , "Unable to add item to Result Update Queue" ) ;
@@ -791,7 +791,7 @@ private ResultsViewModel SelectedResults
791
791
792
792
public Visibility ProgressBarVisibility { get ; set ; }
793
793
public Visibility MainWindowVisibility { get ; set ; }
794
-
794
+
795
795
// This is to be used for determining the visibility status of the main window instead of MainWindowVisibility
796
796
// because it is more accurate and reliable representation than using Visibility as a condition check
797
797
public bool MainWindowVisibilityStatus { get ; set ; } = true ;
@@ -1068,7 +1068,7 @@ private bool CanExternalPreviewSelectedResult(out string path)
1068
1068
path = QueryResultsPreviewed ( ) ? Results . SelectedItem ? . Result ? . Preview . FilePath : string . Empty ;
1069
1069
return ! string . IsNullOrEmpty ( path ) ;
1070
1070
}
1071
-
1071
+
1072
1072
private bool QueryResultsPreviewed ( )
1073
1073
{
1074
1074
var previewed = PreviewSelectedItem == Results . SelectedItem ;
@@ -1278,8 +1278,6 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
1278
1278
// Update the query's IsReQuery property to true if this is a re-query
1279
1279
query . IsReQuery = isReQuery ;
1280
1280
1281
-
1282
-
1283
1281
ICollection < PluginPair > plugins = Array . Empty < PluginPair > ( ) ;
1284
1282
if ( currentIsHomeQuery )
1285
1283
{
@@ -1310,8 +1308,7 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
1310
1308
}
1311
1309
}
1312
1310
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 } >") ) } ") ;
1315
1312
1316
1313
// Do not wait for performance improvement
1317
1314
/*if (string.IsNullOrEmpty(query.ActionKeyword))
@@ -1339,6 +1336,12 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
1339
1336
Task [ ] tasks ;
1340
1337
if ( currentIsHomeQuery )
1341
1338
{
1339
+ if ( ShouldClearExistingResultsForNonQuery ( plugins ) )
1340
+ {
1341
+ Results . Clear ( ) ;
1342
+ App . API . LogDebug ( ClassName , $ "Existing results are cleared for non-query") ;
1343
+ }
1344
+
1342
1345
tasks = plugins . Select ( plugin => plugin . Metadata . HomeDisabled switch
1343
1346
{
1344
1347
false => QueryTaskAsync ( plugin , currentCancellationToken ) ,
@@ -1430,7 +1433,7 @@ await PluginManager.QueryHomeForPluginAsync(plugin, query, token) :
1430
1433
App . API . LogDebug ( ClassName , $ "Update results for plugin <{ plugin . Metadata . Name } >") ;
1431
1434
1432
1435
// 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 ) ;
1434
1437
_lastQuery = query ;
1435
1438
_previousIsHomeQuery = currentIsHomeQuery ;
1436
1439
@@ -1452,8 +1455,13 @@ void QueryHistoryTask(CancellationToken token)
1452
1455
1453
1456
App . API . LogDebug ( ClassName , $ "Update results for history") ;
1454
1457
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
+
1455
1463
if ( ! _resultsUpdateChannelWriter . TryWrite ( new ResultsForUpdate ( results , _historyMetadata , query ,
1456
- token ) ) )
1464
+ token , reSelect , shouldClearExistingResults ) ) )
1457
1465
{
1458
1466
App . API . LogError ( ClassName , "Unable to add item to Result Update Queue" ) ;
1459
1467
}
@@ -1539,7 +1547,9 @@ private async Task BuildQueryAsync(IEnumerable<BaseBuiltinShortcutModel> builtIn
1539
1547
1540
1548
/// <summary>
1541
1549
/// 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
1543
1553
/// either from plugins with matching action keywords or global action keyword, but not both. So when the current results are from plugins
1544
1554
/// 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,
1545
1555
/// and vice versa. The same applies to home page query results.
@@ -1550,19 +1560,39 @@ private async Task BuildQueryAsync(IEnumerable<BaseBuiltinShortcutModel> builtIn
1550
1560
/// <param name="query">The current query.</param>
1551
1561
/// <param name="currentIsHomeQuery">A flag indicating if the current query is a home query.</param>
1552
1562
/// <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 )
1554
1564
{
1555
1565
// If previous or current results are from home query, we need to clear them
1556
1566
if ( _previousIsHomeQuery || currentIsHomeQuery )
1557
1567
{
1558
- App . API . LogDebug ( ClassName , $ "Cleared old results") ;
1568
+ App . API . LogDebug ( ClassName , $ "Existing results should be cleared for query ") ;
1559
1569
return true ;
1560
1570
}
1561
1571
1562
1572
// If the last and current query are not home query type, we need to check the action keyword
1563
1573
if ( _lastQuery ? . ActionKeyword != query ? . ActionKeyword )
1564
1574
{
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") ;
1566
1596
return true ;
1567
1597
}
1568
1598
0 commit comments