Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

git_panel: Focus back on commit editor when expanded (#59901)

Dino25ea3395528a
diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs
index de75268eb48..d22220af2a2 100644
--- a/crates/git_ui/src/git_panel.rs
+++ b/crates/git_ui/src/git_panel.rs
@@ -7151,7 +7151,7 @@ impl Render for GitPanel {
impl Focusable for GitPanel {
fn focus_handle(&self, cx: &App) -> gpui::FocusHandle {
- if self.entries.is_empty() {
+ if self.entries.is_empty() || self.commit_editor_expanded {
self.commit_editor.focus_handle(cx)
} else {
self.focus_handle.clone()
@@ -9984,4 +9984,45 @@ mod tests {
));
});
}
+
+ #[gpui::test]
+ async fn test_focus_handle(cx: &mut TestAppContext) {
+ init_test(cx);
+
+ let (_project, workspace, panel, mut cx) = setup_git_panel_with_changes(
+ cx,
+ json!({
+ ".git": {},
+ "tracked": "tracked\n",
+ }),
+ &[("tracked", StatusCode::Modified)],
+ )
+ .await;
+
+ workspace.update_in(&mut cx, |workspace, window, cx| {
+ workspace.add_panel(panel.clone(), window, cx);
+ });
+
+ // With changes present and the editor not expanded, the panel's own
+ // focus handle should be returned, in order for
+ // `git_panel::ToggleFocus` to focus on the panel itself.
+ panel.update_in(&mut cx, |panel, _window, cx| {
+ assert!(!panel.entries.is_empty());
+ assert!(!panel.commit_editor_expanded);
+ assert_eq!(panel.focus_handle(cx), panel.focus_handle.clone());
+ });
+
+ // Expand the editor so we can later confirm that toggling focus
+ // actually focuses on the commit editor, seeing as it has been
+ // expanded.
+ panel.update_in(&mut cx, |panel, window, cx| {
+ panel.toggle_fill_commit_editor(&ToggleFillCommitEditor, window, cx);
+ assert!(panel.commit_editor_expanded);
+ });
+
+ cx.dispatch_action(super::ToggleFocus);
+ panel.update_in(&mut cx, |panel, window, cx| {
+ assert!(panel.commit_editor.focus_handle(cx).is_focused(window));
+ });
+ }
}