@@ -34,6 +34,7 @@ public partial class MainViewModel : BaseModel, ISavable, IDisposable
3434 private bool _isQueryRunning ;
3535 private Query _lastQuery ;
3636 private bool _previousIsHomeQuery ;
37+ private bool _needClearResults ;
3738 private string _queryTextBeforeLeaveResults ;
3839 private string _ignoredQueryText ; // Used to ignore query text change when switching between context menu and query results
3940
@@ -1375,7 +1376,15 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
13751376 // nothing to do here
13761377 }
13771378
1378- if ( currentCancellationToken . IsCancellationRequested ) return ;
1379+ // If the query is cancelled, part of results may be added to the results already.
1380+ // But we should not clear results now
1381+ // because typing very fast will cause many calls to Results.Clear() which leads to flickering issue
1382+ // Instead, we should clear the results next time we update the results
1383+ if ( currentCancellationToken . IsCancellationRequested )
1384+ {
1385+ _needClearResults = true ;
1386+ return ;
1387+ }
13791388
13801389 // If QueryTaskAsync or QueryHistoryTask is not called which means that results are not cleared
13811390 // we need to clear the results
@@ -1584,6 +1593,13 @@ private bool ShouldClearExistingResults(Query query, bool currentIsHomeQuery)
15841593 return true ;
15851594 }
15861595
1596+ // If the results are not cleared temporarily, we need to clear this time
1597+ if ( _needClearResults )
1598+ {
1599+ _needClearResults = false ;
1600+ return true ;
1601+ }
1602+
15871603 return false ;
15881604 }
15891605
0 commit comments