diff --git a/assets/keymaps/default-linux.json b/assets/keymaps/default-linux.json index 3bb4b1a565..e7b29adfaf 100644 --- a/assets/keymaps/default-linux.json +++ b/assets/keymaps/default-linux.json @@ -746,6 +746,7 @@ { "context": "GitCommit > Editor", "bindings": { + "escape": "menu::Cancel", "enter": "editor::Newline", "ctrl-enter": "git::Commit", "alt-l": "git::GenerateCommitMessage" diff --git a/assets/keymaps/default-macos.json b/assets/keymaps/default-macos.json index 654e04cac2..3edc8bc8f7 100644 --- a/assets/keymaps/default-macos.json +++ b/assets/keymaps/default-macos.json @@ -31,13 +31,13 @@ "enter": "menu::Confirm", "ctrl-enter": "menu::SecondaryConfirm", "cmd-enter": "menu::SecondaryConfirm", + "cmd-escape": "menu::Cancel", "ctrl-escape": "menu::Cancel", "ctrl-c": "menu::Cancel", "escape": "menu::Cancel", "alt-shift-enter": "menu::Restart", "cmd-shift-w": "workspace::CloseWindow", "shift-escape": "workspace::ToggleZoom", - "cmd-escape": "menu::Cancel", "cmd-o": "workspace::Open", "cmd-=": ["zed::IncreaseBufferFontSize", { "persist": false }], "cmd-+": ["zed::IncreaseBufferFontSize", { "persist": false }], @@ -817,6 +817,7 @@ "use_key_equivalents": true, "bindings": { "enter": "editor::Newline", + "escape": "menu::Cancel", "cmd-enter": "git::Commit", "alt-tab": "git::GenerateCommitMessage" } diff --git a/crates/git_ui/src/commit_modal.rs b/crates/git_ui/src/commit_modal.rs index 8c50accfde..4d948cdb53 100644 --- a/crates/git_ui/src/commit_modal.rs +++ b/crates/git_ui/src/commit_modal.rs @@ -232,8 +232,6 @@ impl CommitModal { } pub fn render_footer(&self, window: &mut Window, cx: &mut Context) -> impl IntoElement { - let git_panel = self.git_panel.clone(); - let (branch, can_commit, tooltip, commit_label, co_authors, generate_commit_message) = self.git_panel.update(cx, |git_panel, cx| { let branch = git_panel @@ -289,6 +287,7 @@ impl CommitModal { x: px(0.0), y: px(-2.0), }); + let focus_handle = self.focus_handle(cx); let close_kb_hint = if let Some(close_kb) = ui::KeyBinding::for_action(&menu::Cancel, window, cx) { @@ -300,12 +299,9 @@ impl CommitModal { None }; - let panel_editor_focus_handle = - git_panel.update(cx, |git_panel, cx| git_panel.editor_focus_handle(cx)); - let commit_button = panel_filled_button(commit_label) .tooltip({ - let panel_editor_focus_handle = panel_editor_focus_handle.clone(); + let panel_editor_focus_handle = focus_handle.clone(); move |window, cx| { Tooltip::for_action_in(tooltip, &Commit, &panel_editor_focus_handle, window, cx) } diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index 8e279063ba..73ef617b07 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -694,10 +694,6 @@ impl GitPanel { } } - pub(crate) fn editor_focus_handle(&self, cx: &mut Context) -> FocusHandle { - self.commit_editor.focus_handle(cx).clone() - } - fn focus_editor(&mut self, _: &FocusEditor, window: &mut Window, cx: &mut Context) { self.commit_editor.update(cx, |editor, cx| { window.focus(&editor.focus_handle(cx)); diff --git a/crates/ui/src/components/keybinding.rs b/crates/ui/src/components/keybinding.rs index 1b048b6dbd..5d1fda8e11 100644 --- a/crates/ui/src/components/keybinding.rs +++ b/crates/ui/src/components/keybinding.rs @@ -29,6 +29,9 @@ impl KeyBinding { /// Returns the highest precedence keybinding for an action. This is the last binding added to /// the keymap. User bindings are added after built-in bindings so that they take precedence. pub fn for_action(action: &dyn Action, window: &mut Window, cx: &App) -> Option { + if let Some(focused) = window.focused(cx) { + return Self::for_action_in(action, &focused, window, cx); + } let key_binding = gpui::Keymap::binding_to_display_from_bindings(&window.bindings_for_action(action)) .cloned()?;