git: Touch up amend UX (#35114)

Follow-up to #26114

- Ensure that the previous commit message is filled in when toggling on
amend mode from the context menu
- Fix keybinding flicker in context menu

Release Notes:

- N/A
This commit is contained in:
Cole Miller 2025-07-28 12:21:07 -04:00 committed by GitHub
parent fd68265efd
commit 3dc36dc7c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 37 additions and 26 deletions

View file

@ -295,11 +295,13 @@ impl CommitModal {
IconPosition::Start,
Some(Box::new(Amend)),
{
let git_panel = git_panel_entity.clone();
move |window, cx| {
git_panel.update(cx, |git_panel, cx| {
git_panel.toggle_amend_pending(&Amend, window, cx);
})
let git_panel = git_panel_entity.downgrade();
move |_, cx| {
git_panel
.update(cx, |git_panel, cx| {
git_panel.toggle_amend_pending(cx);
})
.ok();
}
},
)

View file

@ -3113,6 +3113,7 @@ impl GitPanel {
),
)
.menu({
let git_panel = cx.entity();
let has_previous_commit = self.head_commit(cx).is_some();
let amend = self.amend_pending();
let signoff = self.signoff_enabled;
@ -3129,7 +3130,16 @@ impl GitPanel {
amend,
IconPosition::Start,
Some(Box::new(Amend)),
move |window, cx| window.dispatch_action(Box::new(Amend), cx),
{
let git_panel = git_panel.downgrade();
move |_, cx| {
git_panel
.update(cx, |git_panel, cx| {
git_panel.toggle_amend_pending(cx);
})
.ok();
}
},
)
})
.toggleable_entry(
@ -3500,9 +3510,11 @@ impl GitPanel {
.truncate(),
),
)
.child(panel_button("Cancel").size(ButtonSize::Default).on_click(
cx.listener(|this, _, window, cx| this.toggle_amend_pending(&Amend, window, cx)),
))
.child(
panel_button("Cancel")
.size(ButtonSize::Default)
.on_click(cx.listener(|this, _, _, cx| this.set_amend_pending(false, cx))),
)
}
fn render_previous_commit(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
@ -4263,17 +4275,8 @@ impl GitPanel {
pub fn set_amend_pending(&mut self, value: bool, cx: &mut Context<Self>) {
self.amend_pending = value;
cx.notify();
}
pub fn toggle_amend_pending(
&mut self,
_: &Amend,
_window: &mut Window,
cx: &mut Context<Self>,
) {
self.set_amend_pending(!self.amend_pending, cx);
self.serialize(cx);
cx.notify();
}
pub fn signoff_enabled(&self) -> bool {
@ -4367,6 +4370,13 @@ impl GitPanel {
anchor: path,
});
}
pub(crate) fn toggle_amend_pending(&mut self, cx: &mut Context<Self>) {
self.set_amend_pending(!self.amend_pending, cx);
if self.amend_pending {
self.load_last_commit_message_if_empty(cx);
}
}
}
fn current_language_model(cx: &Context<'_, GitPanel>) -> Option<Arc<dyn LanguageModel>> {
@ -4411,7 +4421,6 @@ impl Render for GitPanel {
.on_action(cx.listener(Self::stage_range))
.on_action(cx.listener(GitPanel::commit))
.on_action(cx.listener(GitPanel::amend))
.on_action(cx.listener(GitPanel::toggle_amend_pending))
.on_action(cx.listener(GitPanel::toggle_signoff_enabled))
.on_action(cx.listener(Self::stage_all))
.on_action(cx.listener(Self::unstage_all))