diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml
index 2847d3bdc1..544926082d 100644
--- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml
+++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml
@@ -16,6 +16,8 @@
VerticalContentAlignment="Stretch"
KeyDown="FilterBox_KeyDown"
PlaceholderText="Type here to search..."
+ PreviewKeyUp="FilterBox_PreviewKeyUp"
+ PreviewKeyDown="FilterBox_PreviewKeyDown"
Style="{StaticResource SearchTextBoxStyle}"
TextChanged="FilterBox_TextChanged" />
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 a635ce21dc..752e7747b6 100644
--- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs
+++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs
@@ -26,6 +26,7 @@ public sealed partial class SearchBar : UserControl,
/// Gets the that we create to track keyboard input and throttle/debounce before we make queries.
///
private readonly DispatcherQueueTimer _debounceTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
+ private bool _isBackspaceHeld;
public PageViewModel? CurrentPageViewModel
{
@@ -129,6 +130,37 @@ public sealed partial class SearchBar : UserControl,
}
}
+ private void FilterBox_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
+ {
+ if (e.Key == VirtualKey.Back)
+ {
+ if (string.IsNullOrEmpty(FilterBox.Text))
+ {
+ if (!_isBackspaceHeld)
+ {
+ // Navigate back on single backspace when empty
+ WeakReferenceMessenger.Default.Send();
+ }
+
+ e.Handled = true;
+ }
+ else
+ {
+ // Mark backspace as held to handle continuous deletion
+ _isBackspaceHeld = true;
+ }
+ }
+ }
+
+ private void FilterBox_PreviewKeyUp(object sender, KeyRoutedEventArgs e)
+ {
+ if (e.Key == VirtualKey.Back)
+ {
+ // Reset the backspace state on key release
+ _isBackspaceHeld = false;
+ }
+ }
+
private void FilterBox_TextChanged(object sender, TextChangedEventArgs e)
{
Debug.WriteLine($"FilterBox_TextChanged: {FilterBox.Text}");