From 7f214ed25a67b34e91a403564321579d7a801dac Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 25 Feb 2025 23:07:55 -0700 Subject: [PATCH] git: Fix cmd-enter (#25628) Closes #ISSUE Release Notes: - N/A --- assets/keymaps/default-linux.json | 6 ++++++ assets/keymaps/default-macos.json | 10 +++++++++- crates/git_ui/src/git_panel.rs | 14 ++------------ crates/git_ui/src/project_diff.rs | 28 ++++++++++++++++++++++------ 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/assets/keymaps/default-linux.json b/assets/keymaps/default-linux.json index 849bb98c91d97f706f6549ce4b7b64279b440955..fc58fb1cd95b17c94bf77f99a1747d0fbae423c6 100644 --- a/assets/keymaps/default-linux.json +++ b/assets/keymaps/default-linux.json @@ -733,6 +733,12 @@ "ctrl-enter": "git::Commit" } }, + { + "context": "GitDiff > Editor", + "bindings": { + "ctrl-enter": "git::Commit" + } + }, { "context": "GitPanel > Editor", "bindings": { diff --git a/assets/keymaps/default-macos.json b/assets/keymaps/default-macos.json index 498d9c8e41875f3e3e72ed28701b8ed28291c314..fe0667f740ef0f1c10c8a14a1bf890e494bfc5e0 100644 --- a/assets/keymaps/default-macos.json +++ b/assets/keymaps/default-macos.json @@ -739,7 +739,15 @@ "alt-down": "git_panel::FocusEditor", "tab": "git_panel::FocusEditor", "shift-tab": "git_panel::FocusEditor", - "escape": "git_panel::ToggleFocus" + "escape": "git_panel::ToggleFocus", + "cmd-enter": "git::Commit" + } + }, + { + "context": "GitDiff > Editor", + "use_key_equivalents": true, + "bindings": { + "cmd-enter": "git::Commit" } }, { diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index 61a90998b39de70fa6b2be50024eeab1051bab7f..8f83f793bb706b3a7e123ce351ac6ef570ba5002 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -80,17 +80,6 @@ pub fn init(cx: &mut App) { workspace.register_action(|workspace, _: &ToggleFocus, window, cx| { workspace.toggle_panel_focus::(window, cx); }); - - // workspace.register_action(|workspace, _: &Commit, window, cx| { - // workspace.open_panel::(window, cx); - // if let Some(git_panel) = workspace.panel::(cx) { - // git_panel - // .read(cx) - // .commit_editor - // .focus_handle(cx) - // .focus(window); - // } - // }); }, ) .detach(); @@ -1116,8 +1105,9 @@ impl GitPanel { .contains_focused(window, cx) { self.commit_changes(window, cx) + } else { + cx.propagate(); } - cx.propagate(); } pub(crate) fn commit_changes(&mut self, window: &mut Window, cx: &mut Context) { diff --git a/crates/git_ui/src/project_diff.rs b/crates/git_ui/src/project_diff.rs index 31a82ba4722636cdde56852bcd363b39f178b687..e9cb953651ce4bf300f837eec4077ffc7bd21c93 100644 --- a/crates/git_ui/src/project_diff.rs +++ b/crates/git_ui/src/project_diff.rs @@ -627,6 +627,7 @@ impl Render for ProjectDiff { div() .track_focus(&self.focus_handle) + .key_context(if is_empty { "EmptyPane" } else { "GitDiff" }) .bg(cx.theme().colors().editor_background) .flex() .items_center() @@ -873,11 +874,17 @@ impl Render for ProjectDiffToolbar { .when( button_states.unstage_all && !button_states.stage_all, |el| { - el.child(Button::new("unstage-all", "Unstage All").on_click( - cx.listener(|this, _, window, cx| { - this.dispatch_panel_action(&UnstageAll, window, cx) - }), - )) + el.child( + Button::new("unstage-all", "Unstage All") + .tooltip(Tooltip::for_action_title_in( + "Unstage all changes", + &UnstageAll, + &focus_handle, + )) + .on_click(cx.listener(|this, _, window, cx| { + this.dispatch_panel_action(&UnstageAll, window, cx) + })), + ) }, ) .when( @@ -889,6 +896,11 @@ impl Render for ProjectDiffToolbar { div().child( Button::new("stage-all", "Stage All") .disabled(!button_states.stage_all) + .tooltip(Tooltip::for_action_title_in( + "Stage all changes", + &StageAll, + &focus_handle, + )) .on_click(cx.listener(|this, _, window, cx| { this.dispatch_panel_action(&StageAll, window, cx) })), @@ -899,8 +911,12 @@ impl Render for ProjectDiffToolbar { .child( Button::new("commit", "Commit") .disabled(!button_states.commit) + .tooltip(Tooltip::for_action_title_in( + "Commit", + &Commit, + &focus_handle, + )) .on_click(cx.listener(|this, _, window, cx| { - // todo this should open modal, not focus panel. this.dispatch_action(&Commit, window, cx); })), ),