diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ListViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ListViewModel.cs index 83dc4018f9..31b2c3c0de 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ListViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ListViewModel.cs @@ -328,7 +328,19 @@ public partial class ListViewModel : PageViewModel, IDisposable } [RelayCommand] - private void UpdateSelectedItem(ListItemViewModel item) + private void UpdateSelectedItem(ListItemViewModel? item) + { + if (item != null) + { + SetSelectedItem(item); + } + else + { + ClearSelectedItem(); + } + } + + private void SetSelectedItem(ListItemViewModel item) { if (!item.SafeSlowInit()) { @@ -357,6 +369,23 @@ public partial class ListViewModel : PageViewModel, IDisposable }); } + private void ClearSelectedItem() + { + // GH #322: + // For inexplicable reasons, if you try updating the command bar and + // the details on the same UI thread tick as updating the list, we'll + // explode + DoOnUiThread( + () => + { + WeakReferenceMessenger.Default.Send(new(null)); + + WeakReferenceMessenger.Default.Send(); + + TextToSuggest = string.Empty; + }); + } + public override void InitializeProperties() { base.InitializeProperties(); diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/ExtViews/ListPage.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/ExtViews/ListPage.xaml.cs index 15ddacd9be..8e2865caa6 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/ExtViews/ListPage.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/ExtViews/ListPage.xaml.cs @@ -124,14 +124,12 @@ public sealed partial class ListPage : Page, [System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "VS is too aggressive at pruning methods bound in XAML")] private void ItemsList_SelectionChanged(object sender, SelectionChangedEventArgs e) { - if (ItemsList.SelectedItem is ListItemViewModel item) + var vm = ViewModel; + var li = ItemsList.SelectedItem as ListItemViewModel; + _ = Task.Run(() => { - var vm = ViewModel; - _ = Task.Run(() => - { - vm?.UpdateSelectedItemCommand.Execute(item); - }); - } + vm?.UpdateSelectedItemCommand.Execute(li); + }); // There's mysterious behavior here, where the selection seemingly // changes to _nothing_ when we're backspacing to a single character. diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml.cs index 869b048dbd..09adffd4fe 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Pages/ShellPage.xaml.cs @@ -418,9 +418,6 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page, { _ = DispatcherQueue.TryEnqueue(() => { - // Also hide our details pane about here, if we had one - HideDetails(); - if (_settingsWindow == null) { _settingsWindow = new SettingsWindow();