From 4f27049305491f2403aefde1e3fb1e6dd8e1e717 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 23 Mar 2022 14:33:22 +0100 Subject: [PATCH] Focus followed items when they become active if the pane is active Co-Authored-By: Nathan Sobo --- crates/server/src/rpc.rs | 3 +-- crates/workspace/src/pane.rs | 2 +- crates/workspace/src/workspace.rs | 3 +++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/server/src/rpc.rs b/crates/server/src/rpc.rs index f8ed78a13f58ae9004122aeb8cff15b30215b2f0..1020fd686a2c38fb7ca0f77ffabd81d21d6c5ada 100644 --- a/crates/server/src/rpc.rs +++ b/crates/server/src/rpc.rs @@ -4311,6 +4311,7 @@ mod tests { .downcast::() .unwrap() }); + assert!(cx_b.read(|cx| editor_b2.is_focused(cx))); assert_eq!( editor_b2.read_with(cx_b, |editor, cx| editor.project_path(cx)), Some((worktree_id, "2.txt").into()) @@ -4349,12 +4350,10 @@ mod tests { .condition(cx_b, |editor, cx| editor.text(cx) == "TWO") .await; - eprintln!("=========================>>>>>>>>"); editor_a1.update(cx_a, |editor, cx| { editor.select_ranges([3..3], None, cx); editor.set_scroll_position(vec2f(0., 100.), cx); }); - eprintln!("=========================<<<<<<<<<"); editor_b1 .condition(cx_b, |editor, cx| editor.selected_ranges(cx) == vec![3..3]) .await; diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 9903d414e411b03b3f268e3775266a076b4b06b0..e04af153ba1d76e6ca48855ea98c397da7bc6ebf 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -485,7 +485,7 @@ impl Pane { cx.notify(); } - fn focus_active_item(&mut self, cx: &mut ViewContext) { + pub fn focus_active_item(&mut self, cx: &mut ViewContext) { if let Some(active_item) = self.active_item() { cx.focus(active_item); } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index ed822a348758ec29c37459776e26f1b4b0c1720b..19208294d75630901ec502bbd06ebcf5b3b1ee91 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -1902,6 +1902,9 @@ impl Workspace { for (pane, item) in items_to_add { Pane::add_item(self, pane.clone(), item.boxed_clone(), false, cx); + if pane == self.active_pane { + pane.update(cx, |pane, cx| pane.focus_active_item(cx)); + } cx.notify(); } None