In diagnostics editor, attempt to open excerpts in a different pane

Max Brunsfeld and Nathan Sobo created

Co-Authored-By: Nathan Sobo <nathan@zed.dev>

Change summary

crates/diagnostics/src/diagnostics.rs | 8 +++++++-
crates/workspace/src/workspace.rs     | 6 ++++++
2 files changed, 13 insertions(+), 1 deletion(-)

Detailed changes

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,

crates/workspace/src/workspace.rs 🔗

@@ -979,6 +979,12 @@ impl Workspace {
         }
     }
 
+    pub fn activate_next_pane(&mut self, cx: &mut ViewContext<Self>) {
+        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<Pane>, cx: &mut ViewContext<Self>) {
         self.active_pane = pane;
         self.status_bar.update(cx, |status_bar, cx| {