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.
This commit is contained in:
Mike Griese
2026-02-20 06:31:46 -06:00
parent 0f87b61dad
commit 101e6bde30
5 changed files with 29 additions and 1 deletions

View File

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

View File

@@ -144,6 +144,16 @@ public partial class SettingsViewModel : INotifyPropertyChanged
}
}
public bool ClearSearchOnGoHome
{
get => _settings.ClearSearchOnGoHome;
set
{
_settings.ClearSearchOnGoHome = value;
Save();
}
}
public int AutoGoBackIntervalIndex
{
get

View File

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

View File

@@ -290,6 +290,10 @@
<controls:SettingsCard x:Uid="Settings_GeneralPage_DisableAnimations_SettingsCard" HeaderIcon="{ui:FontIcon Glyph=&#xE945;}">
<ToggleSwitch IsOn="{x:Bind ViewModel.DisableAnimations, Mode=TwoWay}" />
</controls:SettingsCard>
<controls:SettingsCard x:Uid="Settings_GeneralPage_ClearSearchOnGoHome_SettingsCard" HeaderIcon="{ui:FontIcon Glyph=&#xE8BB;}">
<ToggleSwitch IsOn="{x:Bind ViewModel.ClearSearchOnGoHome, Mode=TwoWay}" />
</controls:SettingsCard>
</StackPanel>
</Grid>
</ScrollViewer>

View File

@@ -413,6 +413,12 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
<data name="Settings_GeneralPage_DisableAnimations_SettingsCard.Description" xml:space="preserve">
<value>Disable animations when switching between pages</value>
</data>
<data name="Settings_GeneralPage_ClearSearchOnGoHome_SettingsCard.Header" xml:space="preserve">
<value>Clear search on go home</value>
</data>
<data name="Settings_GeneralPage_ClearSearchOnGoHome_SettingsCard.Description" xml:space="preserve">
<value>Clear the search box when navigating back to the home page</value>
</data>
<data name="BackButton.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<value>Back</value>
</data>