Skip to content

Commit 99d6199

Browse files
authored
Fix: Fixed crash when typing quickly in the Filter header (#18207)
1 parent 1f14443 commit 99d6199

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/Files.App/ViewModels/ShellViewModel.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public GitProperties EnabledGitProperties
169169
private CancellationTokenSource watcherCTS;
170170
private CancellationTokenSource searchCTS;
171171
private CancellationTokenSource updateTagGroupCTS;
172+
private CancellationTokenSource? filterDebounceCS;
172173

173174
public event EventHandler FocusFilterHeader;
174175

@@ -789,7 +790,20 @@ public string? FilesAndFoldersFilter
789790

790791
private void FilesAndFolderFilterUpdated()
791792
{
792-
_ = ApplyFilesAndFoldersChangesAsync();
793+
if (filterDebounceCS is not null)
794+
{
795+
filterDebounceCS.Cancel();
796+
filterDebounceCS.Dispose();
797+
}
798+
799+
filterDebounceCS = new CancellationTokenSource();
800+
var token = filterDebounceCS.Token;
801+
802+
_ = Task.Delay(250, token)
803+
.ContinueWith(_ => ApplyFilesAndFoldersChangesAsync(), token,
804+
TaskContinuationOptions.OnlyOnRanToCompletion,
805+
TaskScheduler.Default)
806+
.Unwrap();
793807
}
794808

795809

@@ -2796,6 +2810,8 @@ public void UpdateDateDisplay(bool isFormatChange)
27962810
public void Dispose()
27972811
{
27982812
CancelLoadAndClearFiles();
2813+
filterDebounceCS?.Cancel();
2814+
filterDebounceCS?.Dispose();
27992815
App.Logger.LogInformation($"ShellViewModel.Dispose: CurrentFolder={LogPathHelper.GetPathIdentifier(CurrentFolder?.ItemPath)}");
28002816

28012817
StorageTrashBinService.Watcher.ItemAdded -= RecycleBinItemCreatedAsync;

0 commit comments

Comments
 (0)