Skip to content

Commit 324e4af

Browse files
committed
refactor: change the Open Local Repository hotkey to Ctrl+L on Windows/Linux
- Add missing hotkey tooltips - Because on Windows/Linux (WSL), the hotkey `Ctrl+Shift+O` will be parsed as `Key.ImeProcessed`, change the hotkey to open local repository to `Ctrl+L` Signed-off-by: leo <longshuang@msn.cn>
1 parent 80ca735 commit 324e4af

4 files changed

Lines changed: 34 additions & 20 deletions

File tree

src/Views/Hotkeys.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<TextBlock Grid.Row="5" Grid.Column="0" Classes="bold" Text="{OnPlatform Ctrl+N, macOS=⌘+N}"/>
6565
<TextBlock Grid.Row="5" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.Clone}" />
6666

67-
<TextBlock Grid.Row="6" Grid.Column="0" Classes="bold" Text="{OnPlatform Ctrl+Shift+O, macOS=⌘+⇧+O}"/>
67+
<TextBlock Grid.Row="6" Grid.Column="0" Classes="bold" Text="{OnPlatform Ctrl+L, macOS=⌘+⇧+O}"/>
6868
<TextBlock Grid.Row="6" Grid.Column="1" Margin="16,0,0,0" Text="{DynamicResource Text.Hotkeys.Global.OpenLocalRepository}" />
6969

7070
<TextBlock Grid.Row="7" Grid.Column="0" Classes="bold" Text="{OnPlatform Ctrl+Alt+P, macOS=⌘+⌥+P}"/>

src/Views/Launcher.axaml.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ protected override async void OnKeyDown(KeyEventArgs e)
143143
}
144144

145145
// Register hotkeys for Windows/Linux (macOS has registered these keys in system menu bar)
146-
if (!OperatingSystem.IsMacOS())
146+
var isMacOS = OperatingSystem.IsMacOS();
147+
var cmdKey = isMacOS ? KeyModifiers.Meta : KeyModifiers.Control;
148+
if (!isMacOS)
147149
{
148150
if (e is { KeyModifiers: KeyModifiers.Control, Key: Key.OemComma })
149151
{
@@ -178,8 +180,6 @@ protected override async void OnKeyDown(KeyEventArgs e)
178180
return;
179181
}
180182

181-
var cmdKey = OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control;
182-
183183
if (vm.CommandPalette != null)
184184
{
185185
if (e.Key == Key.Escape)
@@ -199,6 +199,19 @@ protected override async void OnKeyDown(KeyEventArgs e)
199199
return;
200200
}
201201

202+
// macOS: Cmd+Shift+O to open local repository, Windows/Linux: Ctrl+L to open local repository.
203+
// It's because that Ctrl+Shift+O doesn't work on Windows/Linux(WSL). The e.Key is parsed as Key.ImeProcessed...
204+
if ((isMacOS && e is { Key: Key.O, KeyModifiers: KeyModifiers.Meta | KeyModifiers.Shift }) ||
205+
(!isMacOS && e is { Key: Key.L, KeyModifiers: KeyModifiers.Control }))
206+
{
207+
if (vm.ActivePage.Data is not ViewModels.Welcome)
208+
vm.AddNewTab();
209+
210+
ViewModels.Welcome.Instance.OpenLocalRepository();
211+
e.Handled = true;
212+
return;
213+
}
214+
202215
if (e.KeyModifiers.HasFlag(cmdKey))
203216
{
204217
if (e.Key == Key.W)
@@ -218,33 +231,23 @@ protected override async void OnKeyDown(KeyEventArgs e)
218231
return;
219232
}
220233

221-
if (e.Key == Key.O && e.KeyModifiers.HasFlag(KeyModifiers.Shift))
222-
{
223-
if (vm.ActivePage.Data is not ViewModels.Welcome)
224-
vm.AddNewTab();
225-
226-
ViewModels.Welcome.Instance.OpenLocalRepository();
227-
e.Handled = true;
228-
return;
229-
}
230-
231234
if (e.Key == Key.T && e.KeyModifiers == cmdKey)
232235
{
233236
vm.AddNewTab();
234237
e.Handled = true;
235238
return;
236239
}
237240

238-
if ((OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Alt) && e.Key == Key.Right) ||
239-
(!OperatingSystem.IsMacOS() && !e.KeyModifiers.HasFlag(KeyModifiers.Shift) && e.Key == Key.Tab))
241+
if ((isMacOS && e.KeyModifiers.HasFlag(KeyModifiers.Alt) && e.Key == Key.Right) ||
242+
(!isMacOS && !e.KeyModifiers.HasFlag(KeyModifiers.Shift) && e.Key == Key.Tab))
240243
{
241244
vm.GotoNextTab();
242245
e.Handled = true;
243246
return;
244247
}
245248

246-
if ((OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Alt) && e.Key == Key.Left) ||
247-
(!OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Shift) && e.Key == Key.Tab))
249+
if ((isMacOS && e.KeyModifiers.HasFlag(KeyModifiers.Alt) && e.Key == Key.Left) ||
250+
(!isMacOS && e.KeyModifiers.HasFlag(KeyModifiers.Shift) && e.Key == Key.Tab))
248251
{
249252
vm.GotoPrevTab();
250253
e.Handled = true;

src/Views/RepositoryToolbar.axaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.IO;
34

@@ -25,6 +26,7 @@ private void OpenWithExternalTools(object sender, RoutedEventArgs ev)
2526
if (!Directory.Exists(fullpath))
2627
return;
2728

29+
var isMacOS = OperatingSystem.IsMacOS();
2830
var menu = new ContextMenu();
2931
menu.Placement = PlacementMode.BottomEdgeAlignedLeft;
3032

@@ -35,6 +37,7 @@ private void OpenWithExternalTools(object sender, RoutedEventArgs ev)
3537
var explore = new MenuItem();
3638
explore.Header = App.Text("Repository.Explore");
3739
explore.Icon = this.CreateMenuIcon("Icons.Explore");
40+
explore.Tag = isMacOS ? "⌘+E" : "Ctrl+E";
3841
explore.Click += (_, e) =>
3942
{
4043
Native.OS.OpenInFileManager(fullpath);
@@ -44,6 +47,7 @@ private void OpenWithExternalTools(object sender, RoutedEventArgs ev)
4447
var terminal = new MenuItem();
4548
terminal.Header = App.Text("Repository.Terminal");
4649
terminal.Icon = this.CreateMenuIcon("Icons.Terminal");
50+
terminal.Tag = isMacOS ? "Λ+`" : "Ctrl+`";
4751
terminal.Click += (_, e) =>
4852
{
4953
Native.OS.OpenTerminal(fullpath);

src/Views/WelcomeToolbar.axaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,20 @@
2424
<TextBlock>
2525
<Run Text="{DynamicResource Text.Welcome.OpenOrInit}"/>
2626
<Run Text=" "/>
27-
<Run Text="{OnPlatform Ctrl+Shift+O, macOS=⌘+⇧+O}" FontSize="11" Foreground="{DynamicResource MenuFlyoutItemKeyboardAcceleratorTextForeground}"/>
27+
<Run Text="{OnPlatform Ctrl+L, macOS=⌘+⇧+O}" FontSize="11" Foreground="{DynamicResource MenuFlyoutItemKeyboardAcceleratorTextForeground}"/>
2828
</TextBlock>
2929
</ToolTip.Tip>
3030
<Path Width="14" Height="14" Data="{StaticResource Icons.Folder.Open}" Margin="0,2,0,0"/>
3131
</Button>
3232

33-
<Button Classes="icon_button" Width="32" Command="{Binding OpenTerminal}" ToolTip.Tip="{DynamicResource Text.Welcome.OpenTerminal}">
33+
<Button Classes="icon_button" Width="32" Command="{Binding OpenTerminal}">
34+
<ToolTip.Tip>
35+
<TextBlock>
36+
<Run Text="{DynamicResource Text.Welcome.OpenTerminal}"/>
37+
<Run Text=" "/>
38+
<Run Text="{OnPlatform Ctrl+`, macOS=Λ+`}" FontSize="11" Foreground="{DynamicResource MenuFlyoutItemKeyboardAcceleratorTextForeground}"/>
39+
</TextBlock>
40+
</ToolTip.Tip>
3441
<Path Width="13" Height="13" Data="{StaticResource Icons.Terminal}"/>
3542
</Button>
3643
</StackPanel>

0 commit comments

Comments
 (0)