From 4c3698b17147c1caf9766beb5346b4e0c40fc836 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 22 Apr 2025 10:30:19 +0800 Subject: [PATCH] feature: use `F1` to quick open the `Keyboard Shortcuts Reference` dialog (#1225) Signed-off-by: leo --- src/App.axaml | 2 +- src/Views/Hotkeys.axaml.cs | 10 ++++++++++ src/Views/Launcher.axaml.cs | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/App.axaml b/src/App.axaml index 73b97017..186022d5 100644 --- a/src/App.axaml +++ b/src/App.axaml @@ -35,7 +35,7 @@ - + diff --git a/src/Views/Hotkeys.axaml.cs b/src/Views/Hotkeys.axaml.cs index d8b5e1a8..ea293b0a 100644 --- a/src/Views/Hotkeys.axaml.cs +++ b/src/Views/Hotkeys.axaml.cs @@ -1,3 +1,5 @@ +using Avalonia.Input; + namespace SourceGit.Views { public partial class Hotkeys : ChromelessWindow @@ -6,5 +8,13 @@ namespace SourceGit.Views { InitializeComponent(); } + + protected override void OnKeyDown(KeyEventArgs e) + { + base.OnKeyDown(e); + + if (!e.Handled && e.Key == Key.Escape) + Close(); + } } } diff --git a/src/Views/Launcher.axaml.cs b/src/Views/Launcher.axaml.cs index c19e6bdd..84364ee0 100644 --- a/src/Views/Launcher.axaml.cs +++ b/src/Views/Launcher.axaml.cs @@ -141,6 +141,13 @@ namespace SourceGit.Views return; } + // F1 opens preference dialog (macOS use hotkeys in system menu bar) + if (!OperatingSystem.IsMacOS() && e.Key == Key.F1) + { + App.ShowWindow(new Hotkeys(), true); + return; + } + // Ctrl+Q quits the application (macOS use hotkeys in system menu bar) if (!OperatingSystem.IsMacOS() && e.KeyModifiers == KeyModifiers.Control && e.Key == Key.Q) {