git_ui: Fix commit/amend telemetry and amend click from commit modal (#28795)
Release Notes: - N/A
This commit is contained in:
parent
c7e80c80c6
commit
92dc812aea
2 changed files with 122 additions and 64 deletions
|
@ -271,7 +271,7 @@ impl CommitModal {
|
||||||
.when_some(keybinding_target.clone(), |el, keybinding_target| {
|
.when_some(keybinding_target.clone(), |el, keybinding_target| {
|
||||||
el.context(keybinding_target.clone())
|
el.context(keybinding_target.clone())
|
||||||
})
|
})
|
||||||
.action("Amend...", Amend.boxed_clone())
|
.action("Amend", Amend.boxed_clone())
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
.with_handle(self.commit_menu_handle.clone())
|
.with_handle(self.commit_menu_handle.clone())
|
||||||
|
@ -407,9 +407,18 @@ impl CommitModal {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.disabled(!can_commit)
|
.disabled(!can_commit)
|
||||||
.on_click(move |_, window, cx| {
|
.on_click(cx.listener(move |this, _: &ClickEvent, window, cx| {
|
||||||
window.dispatch_action(Box::new(git::Commit), cx);
|
telemetry::event!("Git Amended", source = "Git Modal");
|
||||||
}),
|
this.git_panel.update(cx, |git_panel, cx| {
|
||||||
|
git_panel.set_amend_pending(false, cx);
|
||||||
|
git_panel.commit_changes(
|
||||||
|
CommitOptions { amend: true },
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
cx.emit(DismissEvent);
|
||||||
|
})),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.when(!is_amend_pending, |this| {
|
.when(!is_amend_pending, |this| {
|
||||||
|
@ -425,9 +434,17 @@ impl CommitModal {
|
||||||
.child(Label::new(commit_label).size(LabelSize::Small))
|
.child(Label::new(commit_label).size(LabelSize::Small))
|
||||||
.mr_0p5(),
|
.mr_0p5(),
|
||||||
)
|
)
|
||||||
.on_click(move |_, window, cx| {
|
.on_click(cx.listener(move |this, _: &ClickEvent, window, cx| {
|
||||||
window.dispatch_action(Box::new(git::Commit), cx);
|
telemetry::event!("Git Committed", source = "Git Modal");
|
||||||
})
|
this.git_panel.update(cx, |git_panel, cx| {
|
||||||
|
git_panel.commit_changes(
|
||||||
|
CommitOptions { amend: false },
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
cx.emit(DismissEvent);
|
||||||
|
}))
|
||||||
.disabled(!can_commit)
|
.disabled(!can_commit)
|
||||||
.tooltip({
|
.tooltip({
|
||||||
let focus_handle = focus_handle.clone();
|
let focus_handle = focus_handle.clone();
|
||||||
|
@ -473,9 +490,22 @@ impl CommitModal {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.disabled(!can_commit)
|
.disabled(!can_commit)
|
||||||
.on_click(move |_, window, cx| {
|
.on_click(cx.listener(
|
||||||
window.dispatch_action(Box::new(git::Commit), cx);
|
move |this, _: &ClickEvent, window, cx| {
|
||||||
}),
|
telemetry::event!(
|
||||||
|
"Git Committed",
|
||||||
|
source = "Git Modal"
|
||||||
|
);
|
||||||
|
this.git_panel.update(cx, |git_panel, cx| {
|
||||||
|
git_panel.commit_changes(
|
||||||
|
CommitOptions { amend: false },
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
cx.emit(DismissEvent);
|
||||||
|
},
|
||||||
|
)),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
|
@ -503,26 +533,18 @@ impl CommitModal {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn amend(&mut self, _: &git::Amend, window: &mut Window, cx: &mut Context<Self>) {
|
fn amend(&mut self, _: &git::Amend, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
if self
|
if !self.git_panel.read(cx).amend_pending() {
|
||||||
.commit_editor
|
self.git_panel.update(cx, |git_panel, cx| {
|
||||||
.focus_handle(cx)
|
git_panel.set_amend_pending(true, cx);
|
||||||
.contains_focused(window, cx)
|
git_panel.load_last_commit_message_if_empty(cx);
|
||||||
{
|
});
|
||||||
if !self.git_panel.read(cx).amend_pending() {
|
|
||||||
self.git_panel.update(cx, |git_panel, cx| {
|
|
||||||
git_panel.set_amend_pending(true, cx);
|
|
||||||
git_panel.load_last_commit_message_if_empty(cx);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
telemetry::event!("Git Amended", source = "Git Panel");
|
|
||||||
self.git_panel.update(cx, |git_panel, cx| {
|
|
||||||
git_panel.set_amend_pending(false, cx);
|
|
||||||
git_panel.commit_changes(CommitOptions { amend: true }, window, cx);
|
|
||||||
});
|
|
||||||
cx.emit(DismissEvent);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
cx.propagate();
|
telemetry::event!("Git Amended", source = "Git Modal");
|
||||||
|
self.git_panel.update(cx, |git_panel, cx| {
|
||||||
|
git_panel.set_amend_pending(false, cx);
|
||||||
|
git_panel.commit_changes(CommitOptions { amend: true }, window, cx);
|
||||||
|
});
|
||||||
|
cx.emit(DismissEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1434,6 +1434,25 @@ impl GitPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn amend(&mut self, _: &git::Amend, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
if self
|
||||||
|
.commit_editor
|
||||||
|
.focus_handle(cx)
|
||||||
|
.contains_focused(window, cx)
|
||||||
|
{
|
||||||
|
if !self.amend_pending {
|
||||||
|
self.set_amend_pending(true, cx);
|
||||||
|
self.load_last_commit_message_if_empty(cx);
|
||||||
|
} else {
|
||||||
|
telemetry::event!("Git Amended", source = "Git Panel");
|
||||||
|
self.set_amend_pending(false, cx);
|
||||||
|
self.commit_changes(CommitOptions { amend: true }, window, cx);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cx.propagate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load_last_commit_message_if_empty(&mut self, 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) {
|
if !self.commit_editor.read(cx).is_empty(cx) {
|
||||||
return;
|
return;
|
||||||
|
@ -1467,30 +1486,9 @@ impl GitPanel {
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn amend(&mut self, _: &git::Amend, window: &mut Window, cx: &mut Context<Self>) {
|
|
||||||
if self
|
|
||||||
.commit_editor
|
|
||||||
.focus_handle(cx)
|
|
||||||
.contains_focused(window, cx)
|
|
||||||
{
|
|
||||||
if !self.amend_pending {
|
|
||||||
self.amend_pending = true;
|
|
||||||
cx.notify();
|
|
||||||
self.load_last_commit_message_if_empty(cx);
|
|
||||||
} else {
|
|
||||||
telemetry::event!("Git Amended", source = "Git Panel");
|
|
||||||
self.amend_pending = false;
|
|
||||||
self.commit_changes(CommitOptions { amend: true }, window, cx);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cx.propagate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn cancel(&mut self, _: &git::Cancel, _: &mut Window, cx: &mut Context<Self>) {
|
fn cancel(&mut self, _: &git::Cancel, _: &mut Window, cx: &mut Context<Self>) {
|
||||||
if self.amend_pending {
|
if self.amend_pending {
|
||||||
self.amend_pending = false;
|
self.set_amend_pending(false, cx);
|
||||||
cx.notify();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2816,7 +2814,7 @@ impl GitPanel {
|
||||||
.when_some(keybinding_target.clone(), |el, keybinding_target| {
|
.when_some(keybinding_target.clone(), |el, keybinding_target| {
|
||||||
el.context(keybinding_target.clone())
|
el.context(keybinding_target.clone())
|
||||||
})
|
})
|
||||||
.action("Amend...", Amend.boxed_clone())
|
.action("Amend", Amend.boxed_clone())
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
.anchor(Corner::TopRight)
|
.anchor(Corner::TopRight)
|
||||||
|
@ -3082,11 +3080,29 @@ impl GitPanel {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.disabled(!can_commit || self.modal_open)
|
.disabled(!can_commit || self.modal_open)
|
||||||
.on_click(move |_, window, cx| {
|
.on_click({
|
||||||
window.dispatch_action(
|
let git_panel = git_panel.downgrade();
|
||||||
Box::new(git::Amend),
|
move |_, window, cx| {
|
||||||
cx,
|
telemetry::event!(
|
||||||
);
|
"Git Amended",
|
||||||
|
source = "Git Panel"
|
||||||
|
);
|
||||||
|
git_panel
|
||||||
|
.update(cx, |git_panel, cx| {
|
||||||
|
git_panel
|
||||||
|
.set_amend_pending(
|
||||||
|
false, cx,
|
||||||
|
);
|
||||||
|
git_panel.commit_changes(
|
||||||
|
CommitOptions {
|
||||||
|
amend: true,
|
||||||
|
},
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -3110,6 +3126,10 @@ impl GitPanel {
|
||||||
.on_click({
|
.on_click({
|
||||||
let git_panel = git_panel.downgrade();
|
let git_panel = git_panel.downgrade();
|
||||||
move |_, window, cx| {
|
move |_, window, cx| {
|
||||||
|
telemetry::event!(
|
||||||
|
"Git Committed",
|
||||||
|
source = "Git Panel"
|
||||||
|
);
|
||||||
git_panel
|
git_panel
|
||||||
.update(cx, |git_panel, cx| {
|
.update(cx, |git_panel, cx| {
|
||||||
git_panel.commit_changes(
|
git_panel.commit_changes(
|
||||||
|
@ -3170,11 +3190,25 @@ impl GitPanel {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.disabled(!can_commit || self.modal_open)
|
.disabled(!can_commit || self.modal_open)
|
||||||
.on_click(move |_, window, cx| {
|
.on_click({
|
||||||
window.dispatch_action(
|
let git_panel = git_panel.downgrade();
|
||||||
Box::new(git::Commit),
|
move |_, window, cx| {
|
||||||
cx,
|
telemetry::event!(
|
||||||
);
|
"Git Committed",
|
||||||
|
source = "Git Panel"
|
||||||
|
);
|
||||||
|
git_panel
|
||||||
|
.update(cx, |git_panel, cx| {
|
||||||
|
git_panel.commit_changes(
|
||||||
|
CommitOptions {
|
||||||
|
amend: false,
|
||||||
|
},
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
@ -3234,8 +3268,10 @@ impl GitPanel {
|
||||||
.px(px(8.))
|
.px(px(8.))
|
||||||
.border_color(cx.theme().colors().border)
|
.border_color(cx.theme().colors().border)
|
||||||
.child(
|
.child(
|
||||||
Label::new("Your changes will modify your most recent commit. If you want to make these changes as a new commit, you can cancel the amend operation.")
|
Label::new(
|
||||||
.size(LabelSize::Small),
|
"This will update your most recent commit. Cancel to make a new one instead.",
|
||||||
|
)
|
||||||
|
.size(LabelSize::Small),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue