Skip to content

Commit b651835

Browse files
committed
enhance: hotkeys
* add `Shift+Ctrl+Tab` (`⌘+⌥+←` on macOS) to go to previous page * use `ESC` to cancel commit searching * enable `AutoFocusBehaviour` on `CommitChanges` and `RevisionFiles` tab
1 parent 16741c2 commit b651835

File tree

7 files changed

+46
-16
lines changed

7 files changed

+46
-16
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,13 @@
213213
<x:String x:Key="Text.Hotkeys.Global" xml:space="preserve">GLOBAL</x:String>
214214
<x:String x:Key="Text.Hotkeys.Global.CancelPopup" xml:space="preserve">Cancel current popup</x:String>
215215
<x:String x:Key="Text.Hotkeys.Global.CloseTab" xml:space="preserve">Close current page</x:String>
216+
<x:String x:Key="Text.Hotkeys.Global.GotoPrevTab" xml:space="preserve">Go to previous page</x:String>
216217
<x:String x:Key="Text.Hotkeys.Global.GotoNextTab" xml:space="preserve">Go to next page</x:String>
217218
<x:String x:Key="Text.Hotkeys.Global.NewTab" xml:space="preserve">Create new page</x:String>
218219
<x:String x:Key="Text.Hotkeys.Repo" xml:space="preserve">REPOSITORY</x:String>
219220
<x:String x:Key="Text.Hotkeys.Repo.Refresh" xml:space="preserve">Force to reload this repository</x:String>
220221
<x:String x:Key="Text.Hotkeys.Repo.StageOrUnstageSelected" xml:space="preserve">Stage/Unstage selected changes</x:String>
221-
<x:String x:Key="Text.Hotkeys.Repo.ToggleSearch" xml:space="preserve">Toggle commit search</x:String>
222+
<x:String x:Key="Text.Hotkeys.Repo.OpenSearchCommits" xml:space="preserve">Open commit search</x:String>
222223
<x:String x:Key="Text.Hotkeys.Repo.ViewChanges" xml:space="preserve">Switch to 'Changes'</x:String>
223224
<x:String x:Key="Text.Hotkeys.Repo.ViewHistories" xml:space="preserve">Switch to 'Histories'</x:String>
224225
<x:String x:Key="Text.Hotkeys.Repo.ViewStashes" xml:space="preserve">Switch to 'Stashes'</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,13 @@
213213
<x:String x:Key="Text.Hotkeys.Global" xml:space="preserve">全局快捷键</x:String>
214214
<x:String x:Key="Text.Hotkeys.Global.CancelPopup" xml:space="preserve">取消弹出面板</x:String>
215215
<x:String x:Key="Text.Hotkeys.Global.CloseTab" xml:space="preserve">关闭当前页面</x:String>
216+
<x:String x:Key="Text.Hotkeys.Global.GotoPrevTab" xml:space="preserve">切换到上一个页面</x:String>
216217
<x:String x:Key="Text.Hotkeys.Global.GotoNextTab" xml:space="preserve">切换到下一个页面</x:String>
217218
<x:String x:Key="Text.Hotkeys.Global.NewTab" xml:space="preserve">新建页面</x:String>
218219
<x:String x:Key="Text.Hotkeys.Repo" xml:space="preserve">仓库页面快捷键</x:String>
219220
<x:String x:Key="Text.Hotkeys.Repo.Refresh" xml:space="preserve">重新加载仓库状态</x:String>
220221
<x:String x:Key="Text.Hotkeys.Repo.StageOrUnstageSelected" xml:space="preserve">将选中的变更暂存或从暂存列表中移除</x:String>
221-
<x:String x:Key="Text.Hotkeys.Repo.ToggleSearch" xml:space="preserve">打开/关闭历史搜索</x:String>
222+
<x:String x:Key="Text.Hotkeys.Repo.OpenSearchCommits" xml:space="preserve">打开历史搜索</x:String>
222223
<x:String x:Key="Text.Hotkeys.Repo.ViewChanges" xml:space="preserve">显示本地更改</x:String>
223224
<x:String x:Key="Text.Hotkeys.Repo.ViewHistories" xml:space="preserve">显示历史记录</x:String>
224225
<x:String x:Key="Text.Hotkeys.Repo.ViewStashes" xml:space="preserve">显示贮藏列表</x:String>

src/ViewModels/Launcher.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ public void GotoNextTab()
9393
ActivePage = Pages[nextIdx];
9494
}
9595

96+
public void GotoPrevTab()
97+
{
98+
if (Pages.Count == 1)
99+
return;
100+
101+
var activeIdx = Pages.IndexOf(_activePage);
102+
var prevIdx = activeIdx == 0 ? Pages.Count - 1 : activeIdx - 1;
103+
ActivePage = Pages[prevIdx];
104+
}
105+
96106
public void CloseTab(object param)
97107
{
98108
if (Pages.Count == 1)

src/Views/CommitChanges.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}"
2424
Background="Transparent"
2525
Watermark="{DynamicResource Text.CommitDetail.Changes.Search}"
26-
Text="{Binding SearchChangeFilter, Mode=TwoWay}">
26+
Text="{Binding SearchChangeFilter, Mode=TwoWay}"
27+
v:AutoFocusBehaviour.IsEnabled="True">
2728
<TextBox.InnerLeftContent>
2829
<Path Width="14" Height="14" Margin="4,0,0,0" Fill="{DynamicResource Brush.FG2}" Data="{StaticResource Icons.Search}"/>
2930
</TextBox.InnerLeftContent>

src/Views/Hotkeys.axaml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,21 @@
6767
FontSize="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize, Converter={x:Static c:FontSizeModifyConverters.Increase}}"
6868
Margin="0,0,0,8"/>
6969

70-
<Grid RowDefinitions="20,20,20,20" ColumnDefinitions="80,*">
70+
<Grid RowDefinitions="20,20,20,20,20" ColumnDefinitions="150,*">
7171
<TextBlock Grid.Row="0" Grid.Column="0" Classes="monospace bold" Text="{OnPlatform Ctrl+T, macOS=⌘+T}"/>
7272
<TextBlock Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.NewTab}" />
7373

7474
<TextBlock Grid.Row="1" Grid.Column="0" Classes="monospace bold" Text="{OnPlatform Ctrl+W, macOS=⌘+W}" />
7575
<TextBlock Grid.Row="1" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.CloseTab}" />
7676

77-
<TextBlock Grid.Row="2" Grid.Column="0" Classes="monospace bold" Text="{OnPlatform Ctrl+Tab, macOS=⌘+⌥+}"/>
78-
<TextBlock Grid.Row="2" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.GotoNextTab}" />
77+
<TextBlock Grid.Row="2" Grid.Column="0" Classes="monospace bold" Text="{OnPlatform Shift+Ctrl+Tab, macOS=⌘+⌥+}"/>
78+
<TextBlock Grid.Row="2" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.GotoPrevTab}" />
7979

80-
<TextBlock Grid.Row="3" Grid.Column="0" Classes="monospace bold" Text="ESC"/>
81-
<TextBlock Grid.Row="3" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.CancelPopup}" />
80+
<TextBlock Grid.Row="3" Grid.Column="0" Classes="monospace bold" Text="{OnPlatform Ctrl+Tab, macOS=⌘+⌥+→}"/>
81+
<TextBlock Grid.Row="3" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.GotoNextTab}" />
82+
83+
<TextBlock Grid.Row="4" Grid.Column="0" Classes="monospace bold" Text="ESC"/>
84+
<TextBlock Grid.Row="4" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.CancelPopup}" />
8285
</Grid>
8386

8487
<TextBlock Text="{DynamicResource Text.Hotkeys.Repo}"
@@ -87,9 +90,9 @@
8790
FontSize="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize, Converter={x:Static c:FontSizeModifyConverters.Increase}}"
8891
Margin="0,8"/>
8992

90-
<Grid RowDefinitions="20,20,20,20,20,20" ColumnDefinitions="80,*">
93+
<Grid RowDefinitions="20,20,20,20,20,20" ColumnDefinitions="150,*">
9194
<TextBlock Grid.Row="0" Grid.Column="0" Classes="monospace bold" Text="{OnPlatform Ctrl+F, macOS=⌘+F}"/>
92-
<TextBlock Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.ToggleSearch}" />
95+
<TextBlock Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.OpenSearchCommits}" />
9396

9497
<TextBlock Grid.Row="1" Grid.Column="0" Classes="monospace bold" Text="{OnPlatform Ctrl+1, macOS=⌘+1}"/>
9598
<TextBlock Grid.Row="1" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Repo.ViewHistories}" />
@@ -113,14 +116,14 @@
113116
FontSize="{Binding Source={x:Static vm:Preference.Instance}, Path=DefaultFontSize, Converter={x:Static c:FontSizeModifyConverters.Increase}}"
114117
Margin="0,8"/>
115118

116-
<Grid RowDefinitions="20,20,20,20" ColumnDefinitions="80,*">
119+
<Grid RowDefinitions="20,20,20,20" ColumnDefinitions="150,*">
117120
<TextBlock Grid.Row="0" Grid.Column="0" Classes="monospace bold" Text="{OnPlatform Ctrl+F, macOS=⌘+F}"/>
118121
<TextBlock Grid.Row="0" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.TextEditor.Search}" />
119122

120-
<TextBlock Grid.Row="1" Grid.Column="0" Classes="monospace bold" Text="{OnPlatform Shift+F3, macOS=⇧+F3}"/>
123+
<TextBlock Grid.Row="1" Grid.Column="0" Classes="monospace bold" Text="{OnPlatform Shift+F3/Shift+Enter, macOS=⇧+F3/⇧+Enter}"/>
121124
<TextBlock Grid.Row="1" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.TextEditor.GotoPrevMatch}" />
122125

123-
<TextBlock Grid.Row="2" Grid.Column="0" Classes="monospace bold" Text="F3"/>
126+
<TextBlock Grid.Row="2" Grid.Column="0" Classes="monospace bold" Text="F3/Enter"/>
124127
<TextBlock Grid.Row="2" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.TextEditor.GotoNextMatch}" />
125128

126129
<TextBlock Grid.Row="3" Grid.Column="0" Classes="monospace bold" Text="ESC"/>

src/Views/Launcher.axaml.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,19 @@ protected override void OnKeyDown(KeyEventArgs e)
114114
return;
115115
}
116116
else if ((OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Alt) && e.Key == Key.Right) ||
117-
(!OperatingSystem.IsMacOS() && e.Key == Key.Tab))
117+
(!OperatingSystem.IsMacOS() && !e.KeyModifiers.HasFlag(KeyModifiers.Shift) && e.Key == Key.Tab))
118118
{
119119
vm.GotoNextTab();
120120
e.Handled = true;
121121
return;
122122
}
123+
else if ((OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Alt) && e.Key == Key.Left) ||
124+
(!OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Shift) && e.Key == Key.Tab))
125+
{
126+
vm.GotoPrevTab();
127+
e.Handled = true;
128+
return;
129+
}
123130
else if (vm.ActivePage.Data is ViewModels.Repository repo)
124131
{
125132
if (e.Key == Key.D1 || e.Key == Key.NumPad1)
@@ -142,7 +149,7 @@ protected override void OnKeyDown(KeyEventArgs e)
142149
}
143150
else if (e.Key == Key.F)
144151
{
145-
repo.IsSearching = !repo.IsSearching;
152+
repo.IsSearching = true;
146153
e.Handled = true;
147154
return;
148155
}
@@ -151,6 +158,12 @@ protected override void OnKeyDown(KeyEventArgs e)
151158
else if (e.Key == Key.Escape)
152159
{
153160
vm.ActivePage.CancelPopup();
161+
162+
if (vm.ActivePage.Data is ViewModels.Repository repo)
163+
{
164+
repo.IsSearching = false;
165+
}
166+
154167
e.Handled = true;
155168
return;
156169
}

src/Views/RevisionFiles.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}"
2525
Background="Transparent"
2626
Watermark="{DynamicResource Text.CommitDetail.Changes.Search}"
27-
Text="{Binding SearchFileFilter, Mode=TwoWay}">
27+
Text="{Binding SearchFileFilter, Mode=TwoWay}"
28+
v:AutoFocusBehaviour.IsEnabled="True">
2829
<TextBox.InnerLeftContent>
2930
<Path Width="14" Height="14" Margin="4,0,0,0" Fill="{DynamicResource Brush.FG2}" Data="{StaticResource Icons.Search}"/>
3031
</TextBox.InnerLeftContent>

0 commit comments

Comments
 (0)