diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index 00e60f5c4f..779f7f9981 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -15,7 +15,14 @@ use gpui::{ use language::{Bias, Buffer, Diagnostic, DiagnosticEntry, Point, Selection, SelectionGoal}; use postage::watch; use project::{Project, ProjectPath}; -use std::{any::TypeId, cmp::Ordering, mem, ops::Range, path::PathBuf, sync::Arc}; +use std::{ + any::{Any, TypeId}, + cmp::Ordering, + mem, + ops::Range, + path::PathBuf, + sync::Arc, +}; use util::TryFutureExt; use workspace::{ItemNavHistory, Workspace}; @@ -517,10 +524,19 @@ impl workspace::Item for ProjectDiagnostics { fn build_view( handle: ModelHandle, workspace: &Workspace, - _: ItemNavHistory, + nav_history: ItemNavHistory, cx: &mut ViewContext, ) -> Self::View { - ProjectDiagnosticsEditor::new(handle, workspace.weak_handle(), workspace.settings(), cx) + let diagnostics = ProjectDiagnosticsEditor::new( + handle, + workspace.weak_handle(), + workspace.settings(), + cx, + ); + diagnostics + .editor + .update(cx, |editor, _| editor.set_nav_history(Some(nav_history))); + diagnostics } fn project_entry(&self) -> Option { @@ -543,6 +559,11 @@ impl workspace::ItemView for ProjectDiagnosticsEditor { None } + fn navigate(&mut self, data: Box, cx: &mut ViewContext) { + self.editor + .update(cx, |editor, cx| editor.navigate(data, cx)); + } + fn is_dirty(&self, cx: &AppContext) -> bool { self.excerpts.read(cx).read(cx).is_dirty() } @@ -587,12 +608,21 @@ impl workspace::ItemView for ProjectDiagnosticsEditor { where Self: Sized, { - Some(ProjectDiagnosticsEditor::new( + let diagnostics = ProjectDiagnosticsEditor::new( self.model.clone(), self.workspace.clone(), self.settings.clone(), cx, - )) + ); + diagnostics.editor.update(cx, |editor, cx| { + let nav_history = self + .editor + .read(cx) + .nav_history() + .map(|nav_history| ItemNavHistory::new(nav_history.history(), &cx.handle())); + editor.set_nav_history(nav_history); + }); + Some(diagnostics) } fn act_as_type( @@ -609,6 +639,10 @@ impl workspace::ItemView for ProjectDiagnosticsEditor { None } } + + fn deactivated(&mut self, cx: &mut ViewContext) { + self.editor.update(cx, |editor, cx| editor.deactivated(cx)); + } } fn path_header_renderer(buffer: ModelHandle, build_settings: BuildSettings) -> RenderBlock { diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index daca2d2ca7..dc1df79b91 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -470,7 +470,7 @@ impl Editor { clone.nav_history = self .nav_history .as_ref() - .map(|nav_history| nav_history.clone(&cx.handle())); + .map(|nav_history| ItemNavHistory::new(nav_history.history(), &cx.handle())); clone } @@ -2459,6 +2459,14 @@ impl Editor { self.update_selections(vec![selection], Some(Autoscroll::Fit), cx); } + pub fn set_nav_history(&mut self, nav_history: Option) { + self.nav_history = nav_history; + } + + pub fn nav_history(&self) -> Option<&ItemNavHistory> { + self.nav_history.as_ref() + } + fn push_to_nav_history( &self, position: Anchor, diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 6b099b492d..dabf816d02 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -551,11 +551,8 @@ impl ItemNavHistory { } } - pub fn clone(&self, item_view: &ViewHandle) -> Self { - Self { - history: self.history.clone(), - item_view: Rc::new(item_view.downgrade()), - } + pub fn history(&self) -> Rc> { + self.history.clone() } pub fn push(&self, data: Option) {