git_ui: Force commit modal mode from command palette (#28745)
Depending on `git::commit` or `git::amend` action triggered, commit modal opens up in appropriate mode, handling edge cases like if you are already in amend mode, etc. Release Notes: - N/A
This commit is contained in:
parent
e1c42315dc
commit
616d17f517
2 changed files with 59 additions and 74 deletions
|
@ -167,7 +167,7 @@ pub fn register(workspace: &mut Workspace) {
|
|||
workspace.toggle_panel_focus::<GitPanel>(window, cx);
|
||||
});
|
||||
workspace.register_action(|workspace, _: &ExpandCommitEditor, window, cx| {
|
||||
CommitModal::toggle(workspace, window, cx)
|
||||
CommitModal::toggle(workspace, None, window, cx)
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1434,7 +1434,10 @@ impl GitPanel {
|
|||
}
|
||||
}
|
||||
|
||||
fn amend(&mut self, _: &git::Amend, window: &mut Window, cx: &mut Context<Self>) {
|
||||
pub fn load_last_commit_message_if_empty(&mut self, cx: &mut Context<Self>) {
|
||||
if !self.commit_editor.read(cx).is_empty(cx) {
|
||||
return;
|
||||
}
|
||||
let Some(active_repository) = self.active_repository.as_ref() else {
|
||||
return;
|
||||
};
|
||||
|
@ -1448,6 +1451,23 @@ impl GitPanel {
|
|||
else {
|
||||
return;
|
||||
};
|
||||
let detail_task = self.load_commit_details(recent_sha, cx);
|
||||
cx.spawn(async move |this, cx| {
|
||||
if let Ok(message) = detail_task.await.map(|detail| detail.message) {
|
||||
this.update(cx, |this, cx| {
|
||||
this.commit_message_buffer(cx).update(cx, |buffer, cx| {
|
||||
let start = buffer.anchor_before(0);
|
||||
let end = buffer.anchor_after(buffer.len());
|
||||
buffer.edit([(start..end, message)], None, cx);
|
||||
});
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
fn amend(&mut self, _: &git::Amend, window: &mut Window, cx: &mut Context<Self>) {
|
||||
if self
|
||||
.commit_editor
|
||||
.focus_handle(cx)
|
||||
|
@ -1456,22 +1476,7 @@ impl GitPanel {
|
|||
if !self.amend_pending {
|
||||
self.amend_pending = true;
|
||||
cx.notify();
|
||||
if self.commit_editor.read(cx).is_empty(cx) {
|
||||
let detail_task = self.load_commit_details(recent_sha, cx);
|
||||
cx.spawn(async move |this, cx| {
|
||||
if let Ok(message) = detail_task.await.map(|detail| detail.message) {
|
||||
this.update(cx, |this, cx| {
|
||||
this.commit_message_buffer(cx).update(cx, |buffer, cx| {
|
||||
let start = buffer.anchor_before(0);
|
||||
let end = buffer.anchor_after(buffer.len());
|
||||
buffer.edit([(start..end, message)], None, cx);
|
||||
});
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
self.load_last_commit_message_if_empty(cx);
|
||||
} else {
|
||||
telemetry::event!("Git Amended", source = "Git Panel");
|
||||
self.amend_pending = false;
|
||||
|
@ -2859,7 +2864,7 @@ impl GitPanel {
|
|||
window.defer(cx, move |window, cx| {
|
||||
workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
CommitModal::toggle(workspace, window, cx)
|
||||
CommitModal::toggle(workspace, None, window, cx)
|
||||
})
|
||||
.ok();
|
||||
})
|
||||
|
@ -3997,8 +4002,9 @@ impl GitPanel {
|
|||
self.amend_pending
|
||||
}
|
||||
|
||||
pub fn set_amend_pending(&mut self, value: bool) {
|
||||
pub fn set_amend_pending(&mut self, value: bool, cx: &mut Context<Self>) {
|
||||
self.amend_pending = value;
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue