Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
git_panel: Fix focus navigation across Changes and History (#62215)
feeiyud61e80b85deb
diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rsindex b4f36c7b0b1..6735bb57ddc 100644--- a/crates/git_ui/src/git_panel.rs+++ b/crates/git_ui/src/git_panel.rs@@ -1222,7 +1222,7 @@ impl GitPanel {view_mode: GitPanelViewMode::from_settings(cx),tree_expanded_dirs: HashMap::default(),projected_entries_by_path: HashMap::default(),- focus_handle: cx.focus_handle(),+ focus_handle,fs,new_count: 0,new_staged_count: 0,@@ -6306,13 +6306,12 @@ impl GitPanel {return;}self.active_tab = tab;+ self.activation_focus_handle(cx).focus(window, cx);match tab {GitPanelTab::History => {- self.focus_handle.focus(window, cx);self.load_commit_history(cx);}GitPanelTab::Changes => {- self.focus_handle.focus(window, cx);self.set_commit_history(CommitHistory::Loading, cx);self._repo_subscriptions.clear();}@@ -8201,7 +8200,9 @@ impl editor::Addon for GitPanelAddon {impl Panel for GitPanel {fn activation_focus_handle(&self, cx: &App) -> FocusHandle {- if self.entries.is_empty() || self.commit_editor_expanded {+ if self.active_tab == GitPanelTab::Changes+ && (self.entries.is_empty() || self.commit_editor_expanded)+ {self.commit_editor.focus_handle(cx)} else {self.focus_handle.clone()@@ -8809,7 +8810,10 @@ mod tests {use util::path;use util::rel_path::rel_path;- use workspace::{MultiWorkspace, ToolbarItemEvent, ToolbarItemLocation};+ use workspace::{+ ActivatePaneLeft, ActivatePaneRight, MultiWorkspace, ToolbarItemEvent, ToolbarItemLocation,+ item::test::TestItem,+ };use super::*;@@ -12451,6 +12455,54 @@ mod tests {});}+ #[gpui::test]+ async fn test_history_tab_pane_navigation_focuses_rendered_panel(cx: &mut TestAppContext) {+ init_test(cx);++ let (_, _project, workspace, panel, mut cx) =+ setup_git_panel_with_changes(cx, json!({ ".git": {} }), &[]).await;++ let center_item = workspace.update_in(&mut cx, |workspace, window, cx| {+ let center_item = cx.new(TestItem::new);+ workspace.add_item_to_active_pane(+ Box::new(center_item.clone()),+ None,+ true,+ window,+ cx,+ );+ workspace.add_panel(panel.clone(), window, cx);+ workspace.open_panel::<GitPanel>(window, cx);+ center_item+ });+ panel.update_in(&mut cx, |panel, window, cx| {+ assert!(panel.entries.is_empty());+ panel.activate_history_tab(&ActivateHistoryTab, window, cx);+ });+ center_item.update_in(&mut cx, |center_item, window, cx| {+ center_item.focus_handle(cx).focus(window, cx);+ });+ cx.run_until_parked();++ cx.dispatch_action(ActivatePaneRight);+ cx.run_until_parked();++ let history_panel_was_focused = panel.update_in(&mut cx, |panel, window, cx| {+ panel.focus_handle.contains_focused(window, cx)+ });++ cx.dispatch_action(ActivatePaneLeft);+ cx.run_until_parked();++ let center_item_is_focused = center_item.update_in(&mut cx, |center_item, window, cx| {+ center_item.focus_handle(cx).is_focused(window)+ });+ assert!(+ history_panel_was_focused && center_item_is_focused,+ "pane navigation should focus the History panel after moving right and restore the center item after moving left; History panel focused after moving right: {history_panel_was_focused}, center item focused after moving left: {center_item_is_focused}"+ );+ }+#[gpui::test]async fn test_discard_tracked_changes_respects_staging(cx: &mut TestAppContext) {init_test(cx);