From 6538efcd9f57fa7bae9b5b42afc97442262dd1c1 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 28 Oct 2025 14:34:14 +0800 Subject: [PATCH] feature: allows to go back to repository command palette from sub command Signed-off-by: leo --- src/Views/BlameCommandPalette.axaml | 23 ++++++------- src/Views/FileHistoryCommandPalette.axaml | 23 ++++++------- src/Views/MergeCommandPalette.axaml | 23 ++++++------- src/Views/RepositoryCommandPaletteTextBox.cs | 36 ++++++++++++++++++++ 4 files changed, 69 insertions(+), 36 deletions(-) create mode 100644 src/Views/RepositoryCommandPaletteTextBox.cs diff --git a/src/Views/BlameCommandPalette.axaml b/src/Views/BlameCommandPalette.axaml index 00704c0a..b20ffa51 100644 --- a/src/Views/BlameCommandPalette.axaml +++ b/src/Views/BlameCommandPalette.axaml @@ -9,16 +9,15 @@ x:Class="SourceGit.Views.BlameCommandPalette" x:DataType="vm:BlameCommandPalette"> - + + Margin="4,0,0,0" Padding="4,0"> @@ -50,7 +49,7 @@ Data="{StaticResource Icons.Clear}"/> - + - + + Margin="4,0,0,0" Padding="4,0"> @@ -50,7 +49,7 @@ Data="{StaticResource Icons.Clear}"/> - + - + + Margin="4,0,0,0" Padding="4,0"> @@ -51,7 +50,7 @@ Data="{StaticResource Icons.Clear}"/> - + typeof(TextBox); + + protected override void OnKeyDown(KeyEventArgs e) + { + if (e.Key == Key.Back && string.IsNullOrEmpty(Text)) + { + var launcherView = this.FindAncestorOfType(false); + if (launcherView is { DataContext: ViewModels.Launcher launcher } && + launcher.ActivePage is { Data: ViewModels.Repository repo }) + { + launcher.OpenCommandPalette(new ViewModels.RepositoryCommandPalette(launcher, repo)); + e.Handled = true; + return; + } + } + + base.OnKeyDown(e); + } + + protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) + { + base.OnAttachedToVisualTree(e); + Focus(); + } + } +}