From 74c29f1818ebe678acc0d7a411d1d8e08e31f5fd Mon Sep 17 00:00:00 2001 From: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com> Date: Wed, 12 Mar 2025 15:07:51 -0400 Subject: [PATCH] Fix unstage/stage in project diff not working when git panel isn't open (#26575) Closes #ISSUE Release Notes: - Fix Bug where unstage/stage all in project diff wouldn't work while git panel was closed Co-authored-by: Conrad Irwin --- crates/git_ui/src/project_diff.rs | 35 ++++++++++++++++++------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/crates/git_ui/src/project_diff.rs b/crates/git_ui/src/project_diff.rs index 6729f3fcfef471a2009dfc944b9c90c9efe2aa93..0e279ea0fe645cba421d9c3ec4abaade3e862523 100644 --- a/crates/git_ui/src/project_diff.rs +++ b/crates/git_ui/src/project_diff.rs @@ -815,23 +815,30 @@ impl ProjectDiffToolbar { cx.dispatch_action(action.as_ref()); }) } - fn dispatch_panel_action( - &self, - action: &dyn Action, - window: &mut Window, - cx: &mut Context, - ) { + + fn stage_all(&mut self, window: &mut Window, cx: &mut Context) { self.workspace - .read_with(cx, |workspace, cx| { + .update(cx, |workspace, cx| { if let Some(panel) = workspace.panel::(cx) { - panel.focus_handle(cx).focus(window) + panel.update(cx, |panel, cx| { + panel.stage_all(&Default::default(), window, cx); + }); } }) .ok(); - let action = action.boxed_clone(); - cx.defer(move |cx| { - cx.dispatch_action(action.as_ref()); - }) + } + + fn unstage_all(&mut self, window: &mut Window, cx: &mut Context) { + self.workspace + .update(cx, |workspace, cx| { + let Some(panel) = workspace.panel::(cx) else { + return; + }; + panel.update(cx, |panel, cx| { + panel.unstage_all(&Default::default(), window, cx); + }); + }) + .ok(); } } @@ -985,7 +992,7 @@ impl Render for ProjectDiffToolbar { &focus_handle, )) .on_click(cx.listener(|this, _, window, cx| { - this.dispatch_panel_action(&UnstageAll, window, cx) + this.unstage_all(window, cx) })), ) }, @@ -1005,7 +1012,7 @@ impl Render for ProjectDiffToolbar { &focus_handle, )) .on_click(cx.listener(|this, _, window, cx| { - this.dispatch_panel_action(&StageAll, window, cx) + this.stage_all(window, cx) })), ), )