From a0a558318c81cee784cb4db2cb2467f8a6f9ee70 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 10 Jan 2022 16:33:25 -0800 Subject: [PATCH] In diagnostics editor, attempt to open excerpts in a different pane Co-Authored-By: Nathan Sobo --- crates/diagnostics/src/diagnostics.rs | 8 +++++++- crates/workspace/src/workspace.rs | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index 8c31673d41..f58fab4dc0 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -192,7 +192,9 @@ impl ProjectDiagnosticsEditor { workspace.update(cx, |workspace, cx| { for (buffer, ranges) in new_selections_by_buffer { let buffer = BufferItemHandle(buffer); - workspace.activate_pane_for_item(&buffer, cx); + if !workspace.activate_pane_for_item(&buffer, cx) { + workspace.activate_next_pane(cx); + } let editor = workspace .open_item(buffer, cx) .to_any() @@ -561,6 +563,10 @@ impl workspace::ItemView for ProjectDiagnosticsEditor { unreachable!() } + fn should_activate_item_on_event(event: &Self::Event) -> bool { + Editor::should_activate_item_on_event(event) + } + fn should_update_tab_on_event(event: &Event) -> bool { matches!( event, diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index b1eb97ec27..eec0a1d446 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -979,6 +979,12 @@ impl Workspace { } } + pub fn activate_next_pane(&mut self, cx: &mut ViewContext) { + let ix = self.panes.iter().position(|pane| pane == &self.active_pane).unwrap(); + let next_ix = (ix + 1) % self.panes.len(); + self.activate_pane(self.panes[next_ix].clone(), cx); + } + fn activate_pane(&mut self, pane: ViewHandle, cx: &mut ViewContext) { self.active_pane = pane; self.status_bar.update(cx, |status_bar, cx| {