From b8accb86ad3970dd2108c1e9acdae8fd8012967f Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Wed, 24 Jan 2024 10:47:37 +0900 Subject: [PATCH] Update BaseShellPage.cs --- src/Files.App/Views/Shells/BaseShellPage.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Files.App/Views/Shells/BaseShellPage.cs b/src/Files.App/Views/Shells/BaseShellPage.cs index cc972747d217..937bed4f2da9 100644 --- a/src/Files.App/Views/Shells/BaseShellPage.cs +++ b/src/Files.App/Views/Shells/BaseShellPage.cs @@ -459,6 +459,8 @@ protected async void DrivesManager_PropertyChanged(object sender, PropertyChange await DisplayFilesystemConsentDialogAsync(); } + private TaskCompletionSource? _getDisplayNameTCS; + // Ensure that the path bar gets updated for user interaction // whenever the path changes.We will get the individual directories from // the updated, most-current path and add them to the UI. @@ -466,13 +468,26 @@ public async Task UpdatePathUIToWorkingDirectoryAsync(string newWorkingDir, stri { if (string.IsNullOrWhiteSpace(singleItemOverride)) { + // We need override the path bar when searching, so we use TaskCompletionSource + // to ensure that the override occurs after GetDirectoryPathComponentsWithDisplayNameAsync. + var tcs = new TaskCompletionSource(); + _getDisplayNameTCS = tcs; + var components = await StorageFileExtensions.GetDirectoryPathComponentsWithDisplayNameAsync(newWorkingDir); ToolbarViewModel.PathComponents.Clear(); foreach (var component in components) ToolbarViewModel.PathComponents.Add(component); + + tcs.TrySetResult(); + _getDisplayNameTCS = null; } else { + // Wait if awaiting GetDirectoryPathComponentsWithDisplayNameAsync + var tcs = _getDisplayNameTCS; + if (tcs is not null) + await tcs.Task; + // Clear the path UI ToolbarViewModel.PathComponents.Clear(); ToolbarViewModel.IsSingleItemOverride = true;