From 101e6bde304bf8795a0ef0f1666fec877d1deeb2 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Fri, 20 Feb 2026 06:31:46 -0600 Subject: [PATCH] CmdPal: Add a setting to retain search when going home This allows CmdPal to retain the last thing typed when you go back to the home page after running a command. This affects anything that returns a `GoHome` or a `Dismiss`. Closes #39929 Closes #44826 It does not retain the last ran thing as like, the top result. It's too wacky to try to persist that `ICommand` and bring it to the top-level. --- .../Microsoft.CmdPal.UI.ViewModels/SettingsModel.cs | 2 ++ .../SettingsViewModel.cs | 10 ++++++++++ .../Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs | 8 +++++++- .../Microsoft.CmdPal.UI/Settings/AppearancePage.xaml | 4 ++++ .../Microsoft.CmdPal.UI/Strings/en-us/Resources.resw | 6 ++++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsModel.cs index c023c3daae..af57c0f189 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsModel.cs @@ -66,6 +66,8 @@ public partial class SettingsModel : ObservableObject public EscapeKeyBehavior EscapeKeyBehaviorSetting { get; set; } = EscapeKeyBehavior.ClearSearchFirstThenGoBack; + public bool ClearSearchOnGoHome { get; set; } = true; + public UserTheme Theme { get; set; } = UserTheme.Default; public ColorizationMode ColorizationMode { get; set; } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsViewModel.cs index 947a025e69..a667f9f5d5 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsViewModel.cs @@ -144,6 +144,16 @@ public partial class SettingsViewModel : INotifyPropertyChanged } } + public bool ClearSearchOnGoHome + { + get => _settings.ClearSearchOnGoHome; + set + { + _settings.ClearSearchOnGoHome = value; + Save(); + } + } + public int AutoGoBackIntervalIndex { get diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs index ca27af4719..fdbb575802 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs @@ -421,7 +421,13 @@ public sealed partial class SearchBar : UserControl, } } - public void Receive(GoHomeMessage message) => ClearSearch(); + public void Receive(GoHomeMessage message) + { + if (Settings.ClearSearchOnGoHome) + { + ClearSearch(); + } + } public void Receive(FocusSearchBoxMessage message) => FilterBox.Focus(Microsoft.UI.Xaml.FocusState.Programmatic); diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/AppearancePage.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/AppearancePage.xaml index 8a66b54d89..b18a04745a 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/AppearancePage.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/AppearancePage.xaml @@ -290,6 +290,10 @@ + + + + diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Strings/en-us/Resources.resw b/src/modules/cmdpal/Microsoft.CmdPal.UI/Strings/en-us/Resources.resw index 996a6202fc..353efbf91e 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Strings/en-us/Resources.resw +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Strings/en-us/Resources.resw @@ -413,6 +413,12 @@ Right-click to remove the key combination, thereby deactivating the shortcut. Disable animations when switching between pages + + Clear search on go home + + + Clear the search box when navigating back to the home page + Back