Start laying the foundation for a per-pane navigation system
This commit is contained in:
@@ -41,6 +41,7 @@ use std::{
|
||||
iter::{self, FromIterator},
|
||||
mem,
|
||||
ops::{Deref, Range, RangeInclusive, Sub},
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
@@ -48,7 +49,7 @@ use sum_tree::Bias;
|
||||
use text::rope::TextDimension;
|
||||
use theme::{DiagnosticStyle, EditorStyle};
|
||||
use util::post_inc;
|
||||
use workspace::{PathOpener, Workspace};
|
||||
use workspace::{Navigation, PathOpener, Workspace};
|
||||
|
||||
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
|
||||
const MAX_LINE_LEN: usize = 1024;
|
||||
@@ -377,6 +378,7 @@ pub struct Editor {
|
||||
mode: EditorMode,
|
||||
placeholder_text: Option<Arc<str>>,
|
||||
highlighted_rows: Option<Range<u32>>,
|
||||
navigation: Option<Rc<Navigation>>,
|
||||
}
|
||||
|
||||
pub struct EditorSnapshot {
|
||||
@@ -457,6 +459,7 @@ impl Editor {
|
||||
let mut clone = Self::new(self.buffer.clone(), self.build_settings.clone(), cx);
|
||||
clone.scroll_position = self.scroll_position;
|
||||
clone.scroll_top_anchor = self.scroll_top_anchor.clone();
|
||||
clone.navigation = self.navigation.clone();
|
||||
clone
|
||||
}
|
||||
|
||||
@@ -506,6 +509,7 @@ impl Editor {
|
||||
mode: EditorMode::Full,
|
||||
placeholder_text: None,
|
||||
highlighted_rows: None,
|
||||
navigation: None,
|
||||
};
|
||||
let selection = Selection {
|
||||
id: post_inc(&mut this.next_selection_id),
|
||||
|
||||
@@ -10,11 +10,12 @@ use postage::watch;
|
||||
use project::{File, ProjectPath, Worktree};
|
||||
use std::fmt::Write;
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
use text::{Point, Selection};
|
||||
use util::TryFutureExt;
|
||||
use workspace::{
|
||||
ItemHandle, ItemView, ItemViewHandle, PathOpener, Settings, StatusItemView, WeakItemHandle,
|
||||
Workspace,
|
||||
ItemHandle, ItemView, ItemViewHandle, Navigation, PathOpener, Settings, StatusItemView,
|
||||
WeakItemHandle, Workspace,
|
||||
};
|
||||
|
||||
pub struct BufferOpener;
|
||||
@@ -46,16 +47,19 @@ impl ItemHandle for BufferItemHandle {
|
||||
&self,
|
||||
window_id: usize,
|
||||
workspace: &Workspace,
|
||||
navigation: Rc<Navigation>,
|
||||
cx: &mut MutableAppContext,
|
||||
) -> Box<dyn ItemViewHandle> {
|
||||
let buffer = cx.add_model(|cx| MultiBuffer::singleton(self.0.clone(), cx));
|
||||
let weak_buffer = buffer.downgrade();
|
||||
Box::new(cx.add_view(window_id, |cx| {
|
||||
Editor::for_buffer(
|
||||
let mut editor = Editor::for_buffer(
|
||||
buffer,
|
||||
crate::settings_builder(weak_buffer, workspace.settings()),
|
||||
cx,
|
||||
)
|
||||
);
|
||||
editor.navigation = Some(navigation);
|
||||
editor
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -129,6 +133,12 @@ impl ItemView for Editor {
|
||||
Some(self.clone(cx))
|
||||
}
|
||||
|
||||
fn activated(&mut self, cx: &mut ViewContext<Self>) {
|
||||
if let Some(navigation) = self.navigation.as_ref() {
|
||||
navigation.push::<(), _>(None, cx);
|
||||
}
|
||||
}
|
||||
|
||||
fn is_dirty(&self, cx: &AppContext) -> bool {
|
||||
self.buffer().read(cx).read(cx).is_dirty()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user