CmdPal: Add 'Keep previous query' setting to Command Palette (#45742)

## 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>
This commit is contained in:
Michael Jolley
2026-02-22 19:31:50 -08:00
committed by GitHub
parent 009ee75de0
commit 196b9305c3
5 changed files with 28 additions and 1 deletions

View File

@@ -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; }

View File

@@ -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;