@@ -33,7 +33,7 @@ public partial class MainViewModel : BaseModel, ISavable, IDisposable
33
33
34
34
private bool _isQueryRunning ;
35
35
private Query _lastQuery ;
36
- private bool _lastIsHomeQuery ;
36
+ private bool _previousIsHomeQuery ;
37
37
private string _queryTextBeforeLeaveResults ;
38
38
private string _ignoredQueryText ; // Used to ignore query text change when switching between context menu and query results
39
39
@@ -1264,7 +1264,7 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
1264
1264
1265
1265
App . API . LogDebug ( ClassName , $ "Start query with ActionKeyword <{ query . ActionKeyword } > and RawQuery <{ query . RawQuery } >") ;
1266
1266
1267
- var isHomeQuery = query . RawQuery == string . Empty ;
1267
+ var currentIsHomeQuery = query . RawQuery == string . Empty ;
1268
1268
1269
1269
_updateSource ? . Dispose ( ) ;
1270
1270
@@ -1284,14 +1284,10 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
1284
1284
// Update the query's IsReQuery property to true if this is a re-query
1285
1285
query . IsReQuery = isReQuery ;
1286
1286
1287
- // handle the exclusiveness of plugin using action keyword
1288
- RemoveOldQueryResults ( query , isHomeQuery ) ;
1289
-
1290
- _lastQuery = query ;
1291
- _lastIsHomeQuery = isHomeQuery ;
1287
+
1292
1288
1293
1289
ICollection < PluginPair > plugins = Array . Empty < PluginPair > ( ) ;
1294
- if ( isHomeQuery )
1290
+ if ( currentIsHomeQuery )
1295
1291
{
1296
1292
if ( Settings . ShowHomePage )
1297
1293
{
@@ -1347,7 +1343,7 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
1347
1343
// plugins are ICollection, meaning LINQ will get the Count and preallocate Array
1348
1344
1349
1345
Task [ ] tasks ;
1350
- if ( isHomeQuery )
1346
+ if ( currentIsHomeQuery )
1351
1347
{
1352
1348
tasks = plugins . Select ( plugin => plugin . Metadata . HomeDisabled switch
1353
1349
{
@@ -1397,7 +1393,7 @@ async Task QueryTaskAsync(PluginPair plugin, CancellationToken token)
1397
1393
{
1398
1394
App . API . LogDebug ( ClassName , $ "Wait for querying plugin <{ plugin . Metadata . Name } >") ;
1399
1395
1400
- if ( searchDelay && ! isHomeQuery ) // Do not delay for home query
1396
+ if ( searchDelay && ! currentIsHomeQuery ) // Do not delay for home query
1401
1397
{
1402
1398
var searchDelayTime = plugin . Metadata . SearchDelayTime ?? Settings . SearchDelayTime ;
1403
1399
@@ -1410,7 +1406,7 @@ async Task QueryTaskAsync(PluginPair plugin, CancellationToken token)
1410
1406
// Task.Yield will force it to run in ThreadPool
1411
1407
await Task . Yield ( ) ;
1412
1408
1413
- var results = isHomeQuery ?
1409
+ var results = currentIsHomeQuery ?
1414
1410
await PluginManager . QueryHomeForPluginAsync ( plugin , query , token ) :
1415
1411
await PluginManager . QueryForPluginAsync ( plugin , query , token ) ;
1416
1412
@@ -1439,8 +1435,13 @@ await PluginManager.QueryHomeForPluginAsync(plugin, query, token) :
1439
1435
1440
1436
App . API . LogDebug ( ClassName , $ "Update results for plugin <{ plugin . Metadata . Name } >") ;
1441
1437
1438
+ // Indicate if to clear existing results so to show only ones from plugins with action keywords
1439
+ var shouldClearExistingResults = ShouldClearExistingResults ( query , currentIsHomeQuery ) ;
1440
+ _lastQuery = query ;
1441
+ _previousIsHomeQuery = currentIsHomeQuery ;
1442
+
1442
1443
if ( ! _resultsUpdateChannelWriter . TryWrite ( new ResultsForUpdate ( resultsCopy , plugin . Metadata , query ,
1443
- token , reSelect ) ) )
1444
+ token , reSelect , shouldClearExistingResults ) ) )
1444
1445
{
1445
1446
App . API . LogError ( ClassName , "Unable to add item to Result Update Queue" ) ;
1446
1447
}
@@ -1542,25 +1543,36 @@ private async Task BuildQueryAsync(IEnumerable<BaseBuiltinShortcutModel> builtIn
1542
1543
}
1543
1544
}
1544
1545
1545
- private void RemoveOldQueryResults ( Query query , bool isHomeQuery )
1546
+ /// <summary>
1547
+ /// Determines whether the existing search results should be cleared based on the current query and the previous query type.
1548
+ /// This is needed because of the design that treats plugins with action keywords and global action keywords separately. Results are gathered
1549
+ /// either from plugins with matching action keywords or global action keyword, but not both. So when the current results are from plugins
1550
+ /// 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,
1551
+ /// and vice versa. The same applies to home page query results.
1552
+ ///
1553
+ /// There is no need to clear results from global action keyword if a new set of results comes along that is also from global action keywords.
1554
+ /// This is because the removal of obsolete results is handled in ResultsViewModel.NewResults(ICollection<ResultsForUpdate>).
1555
+ /// </summary>
1556
+ /// <param name="query">The current query.</param>
1557
+ /// <param name="currentIsHomeQuery">A flag indicating if the current query is a home query.</param>
1558
+ /// <returns>True if the existing results should be cleared, false otherwise.</returns>
1559
+ private bool ShouldClearExistingResults ( Query query , bool currentIsHomeQuery )
1546
1560
{
1547
- // If last and current query are home query, we don't need to clear the results
1548
- if ( _lastIsHomeQuery && isHomeQuery )
1561
+ // If previous or current results are from home query, we need to clear them
1562
+ if ( _previousIsHomeQuery || currentIsHomeQuery )
1549
1563
{
1550
- return ;
1564
+ App . API . LogDebug ( ClassName , $ "Cleared old results") ;
1565
+ return true ;
1551
1566
}
1552
- // If last or current query is home query, we need to clear the results
1553
- else if ( _lastIsHomeQuery || isHomeQuery )
1554
- {
1555
- App . API . LogDebug ( ClassName , $ "Remove old results") ;
1556
- Results . Clear ( ) ;
1557
- }
1558
- // If last and current query are not home query, we need to check action keyword
1559
- else if ( _lastQuery ? . ActionKeyword != query ? . ActionKeyword )
1567
+
1568
+ // If the last and current query are not home query type, we need to check the action keyword
1569
+ if ( _lastQuery ? . ActionKeyword != query ? . ActionKeyword )
1560
1570
{
1561
- App . API . LogDebug ( ClassName , $ "Remove old results") ;
1562
- Results . Clear ( ) ;
1571
+ App . API . LogDebug ( ClassName , $ "Cleared old results") ;
1572
+ return true ;
1563
1573
}
1574
+
1575
+ return false ;
1564
1576
}
1565
1577
1566
1578
private Result ContextMenuTopMost ( Result result )
0 commit comments