From 196b9305c3aa2a0790ae5a30388a27a19a586087 Mon Sep 17 00:00:00 2001 From: Michael Jolley Date: Sun, 22 Feb 2026 19:31:50 -0800 Subject: [PATCH] CmdPal: Add 'Keep previous query' setting to Command Palette (#45742) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Closes #39929 Adds a new "Keep previous query" toggle to Command Palette settings that preserves the last search text when the palette is reopened after running a command. ## Changes - **`SettingsModel.cs`** — Added `KeepPreviousQuery` bool property (defaults to `false`) - **`SettingsViewModel.cs`** — Added property with auto-save on change - **`GeneralPage.xaml`** — Added toggle switch in the Activation section, below "Highlight search on activate" - **`Resources.resw`** — Added localized header ("Keep previous query") and description ("Preserves the last search text when Command Palette is reopened") - **`SearchBar.xaml.cs`** — `Receive(GoHomeMessage)` now checks the setting and skips `ClearSearch()` when enabled ## Behavior - **Off (default):** No change from current behavior — search text is cleared on dismiss. - **On:** When a command is run and the palette dismisses, the search text is preserved. On reopen, the previous query is still in the search box. Combined with the existing "Highlight search on activate" setting, the text will be pre-selected so the user can immediately retype or press Enter to re-run. ## Validation - Setting off: search clears on dismiss (existing behavior unchanged) - Setting on: search text persists across dismiss/reopen - Setting serializes/deserializes correctly via existing JSON settings infrastructure - No impact on page navigation, escape key behavior, or auto-go-home timer --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Microsoft.CmdPal.UI.ViewModels/SettingsModel.cs | 2 ++ .../SettingsViewModel.cs | 10 ++++++++++ .../Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs | 8 +++++++- .../Microsoft.CmdPal.UI/Settings/GeneralPage.xaml | 3 +++ .../Microsoft.CmdPal.UI/Strings/en-us/Resources.resw | 6 ++++++ 5 files changed, 28 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..7c45395ab7 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsModel.cs @@ -42,6 +42,8 @@ public partial class SettingsModel : ObservableObject public bool HighlightSearchOnActivate { get; set; } = true; + public bool KeepPreviousQuery { get; set; } + public bool ShowSystemTrayIcon { get; set; } = true; public bool IgnoreShortcutWhenFullscreen { 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..affee3fd89 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/SettingsViewModel.cs @@ -104,6 +104,16 @@ public partial class SettingsViewModel : INotifyPropertyChanged } } + public bool KeepPreviousQuery + { + get => _settings.KeepPreviousQuery; + set + { + _settings.KeepPreviousQuery = value; + Save(); + } + } + public int MonitorPositionIndex { get => (int)_settings.SummonOn; 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..678c152e9d 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.KeepPreviousQuery) + { + ClearSearch(); + } + } public void Receive(FocusSearchBoxMessage message) => FilterBox.Focus(Microsoft.UI.Xaml.FocusState.Programmatic); diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/GeneralPage.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/GeneralPage.xaml index bd80615556..bb3110deb3 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/GeneralPage.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/GeneralPage.xaml @@ -68,6 +68,9 @@ + + + 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..d82aa20b96 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 @@ -350,6 +350,12 @@ Right-click to remove the key combination, thereby deactivating the shortcut. Selects the previous search text at launch + + Keep previous query + + + Preserves the last search text when Command Palette is reopened + Show app details