From b651835de00257c8be53a3f0c4f6a55ac835e6f5 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 6 May 2024 10:22:13 +0800 Subject: [PATCH] enhance: hotkeys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add `Shift+Ctrl+Tab` (`⌘+⌥+←` on macOS) to go to previous page * use `ESC` to cancel commit searching * enable `AutoFocusBehaviour` on `CommitChanges` and `RevisionFiles` tab --- src/Resources/Locales/en_US.axaml | 3 ++- src/Resources/Locales/zh_CN.axaml | 3 ++- src/ViewModels/Launcher.cs | 10 ++++++++++ src/Views/CommitChanges.axaml | 3 ++- src/Views/Hotkeys.axaml | 23 +++++++++++++---------- src/Views/Launcher.axaml.cs | 17 +++++++++++++++-- src/Views/RevisionFiles.axaml | 3 ++- 7 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 74a92064..563809eb 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -213,12 +213,13 @@ GLOBAL Cancel current popup Close current page + Go to previous page Go to next page Create new page REPOSITORY Force to reload this repository Stage/Unstage selected changes - Toggle commit search + Open commit search Switch to 'Changes' Switch to 'Histories' Switch to 'Stashes' diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 8a9bd825..76385fe0 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -213,12 +213,13 @@ 全局快捷键 取消弹出面板 关闭当前页面 + 切换到上一个页面 切换到下一个页面 新建页面 仓库页面快捷键 重新加载仓库状态 将选中的变更暂存或从暂存列表中移除 - 打开/关闭历史搜索 + 打开历史搜索 显示本地更改 显示历史记录 显示贮藏列表 diff --git a/src/ViewModels/Launcher.cs b/src/ViewModels/Launcher.cs index 59cf309a..3d1fc1c1 100644 --- a/src/ViewModels/Launcher.cs +++ b/src/ViewModels/Launcher.cs @@ -93,6 +93,16 @@ namespace SourceGit.ViewModels ActivePage = Pages[nextIdx]; } + public void GotoPrevTab() + { + if (Pages.Count == 1) + return; + + var activeIdx = Pages.IndexOf(_activePage); + var prevIdx = activeIdx == 0 ? Pages.Count - 1 : activeIdx - 1; + ActivePage = Pages[prevIdx]; + } + public void CloseTab(object param) { if (Pages.Count == 1) diff --git a/src/Views/CommitChanges.axaml b/src/Views/CommitChanges.axaml index 3720590b..7f1ccc32 100644 --- a/src/Views/CommitChanges.axaml +++ b/src/Views/CommitChanges.axaml @@ -23,7 +23,8 @@ BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}" Background="Transparent" Watermark="{DynamicResource Text.CommitDetail.Changes.Search}" - Text="{Binding SearchChangeFilter, Mode=TwoWay}"> + Text="{Binding SearchChangeFilter, Mode=TwoWay}" + v:AutoFocusBehaviour.IsEnabled="True"> diff --git a/src/Views/Hotkeys.axaml b/src/Views/Hotkeys.axaml index a2d0e068..96f0a9a2 100644 --- a/src/Views/Hotkeys.axaml +++ b/src/Views/Hotkeys.axaml @@ -67,18 +67,21 @@ FontSize="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize, Converter={x:Static c:FontSizeModifyConverters.Increase}}" Margin="0,0,0,8"/> - + - - + + - - + + + + + - + - + @@ -113,14 +116,14 @@ FontSize="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize, Converter={x:Static c:FontSizeModifyConverters.Increase}}" Margin="0,8"/> - + - + - + diff --git a/src/Views/Launcher.axaml.cs b/src/Views/Launcher.axaml.cs index c56de06b..d6f4b54f 100644 --- a/src/Views/Launcher.axaml.cs +++ b/src/Views/Launcher.axaml.cs @@ -114,12 +114,19 @@ namespace SourceGit.Views return; } else if ((OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Alt) && e.Key == Key.Right) || - (!OperatingSystem.IsMacOS() && e.Key == Key.Tab)) + (!OperatingSystem.IsMacOS() && !e.KeyModifiers.HasFlag(KeyModifiers.Shift) && e.Key == Key.Tab)) { vm.GotoNextTab(); e.Handled = true; return; } + else if ((OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Alt) && e.Key == Key.Left) || + (!OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Shift) && e.Key == Key.Tab)) + { + vm.GotoPrevTab(); + e.Handled = true; + return; + } else if (vm.ActivePage.Data is ViewModels.Repository repo) { if (e.Key == Key.D1 || e.Key == Key.NumPad1) @@ -142,7 +149,7 @@ namespace SourceGit.Views } else if (e.Key == Key.F) { - repo.IsSearching = !repo.IsSearching; + repo.IsSearching = true; e.Handled = true; return; } @@ -151,6 +158,12 @@ namespace SourceGit.Views else if (e.Key == Key.Escape) { vm.ActivePage.CancelPopup(); + + if (vm.ActivePage.Data is ViewModels.Repository repo) + { + repo.IsSearching = false; + } + e.Handled = true; return; } diff --git a/src/Views/RevisionFiles.axaml b/src/Views/RevisionFiles.axaml index 2804f627..e91c6e0b 100644 --- a/src/Views/RevisionFiles.axaml +++ b/src/Views/RevisionFiles.axaml @@ -24,7 +24,8 @@ BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}" Background="Transparent" Watermark="{DynamicResource Text.CommitDetail.Changes.Search}" - Text="{Binding SearchFileFilter, Mode=TwoWay}"> + Text="{Binding SearchFileFilter, Mode=TwoWay}" + v:AutoFocusBehaviour.IsEnabled="True">