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_graph: Focus search editor on open (#63002)

Finn Evers075520b968e1
diff --git a/crates/git_ui/src/git_graph.rs b/crates/git_ui/src/git_graph.rs
index 4e67356feca..a37b920a4a8 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<ItemEvent> 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);