From 36ef5aeb8d3d872bad73551d2faf41cd80efdaa4 Mon Sep 17 00:00:00 2001 From: Finn Evers Date: Fri, 21 Aug 2026 10:36:13 +0000 Subject: [PATCH] git_graph: Focus search editor on open (#63002) Release Notes: - The git graph and git history view will now focus the search editor on initial focus --- crates/git_ui/src/git_graph.rs | 59 ++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/crates/git_ui/src/git_graph.rs b/crates/git_ui/src/git_graph.rs index 4e67356fec..a37b920a4a 100644 --- a/crates/git_ui/src/git_graph.rs +++ b/crates/git_ui/src/git_graph.rs @@ -4108,8 +4108,8 @@ impl Render for GitGraph { impl EventEmitter for GitGraph {} impl Focusable for GitGraph { - fn focus_handle(&self, _cx: &App) -> FocusHandle { - self.focus_handle.clone() + fn focus_handle(&self, cx: &App) -> FocusHandle { + self.search_state.editor.read(cx).focus_handle(cx) } } @@ -6449,6 +6449,61 @@ mod tests { }); } + #[gpui::test] + async fn test_focus_handle_focuses_search_editor(cx: &mut TestAppContext) { + init_test(cx); + + let fs = FakeFs::new(cx.executor()); + fs.insert_tree( + Path::new("/project"), + serde_json::json!({ + ".git": {}, + "file.txt": "content", + }), + ) + .await; + + let project = Project::test(fs.clone(), [Path::new("/project")], cx).await; + cx.run_until_parked(); + + let repository = project.read_with(cx, |project, cx| { + project + .active_repository(cx) + .expect("should have a repository") + }); + + let (multi_workspace, cx) = cx.add_window_view(|window, cx| { + workspace::MultiWorkspace::test_new(project.clone(), window, cx) + }); + let workspace_weak = + multi_workspace.read_with(&*cx, |multi, _| multi.workspace().downgrade()); + + let git_graph = cx.new_window_entity(|window, cx| { + GitGraph::new( + repository.read(cx).id, + project.read(cx).git_store().clone(), + workspace_weak, + None, + window, + cx, + ) + }); + cx.run_until_parked(); + + git_graph.update_in(cx, |graph, window, cx| { + window.focus(&graph.focus_handle(cx), cx); + assert!( + graph + .search_state + .editor + .read(cx) + .focus_handle(cx) + .is_focused(window), + "focusing the git graph item should focus the search editor" + ); + }); + } + #[gpui::test] async fn test_row_height_matches_uniform_list_item_height(cx: &mut TestAppContext) { init_test(cx);