Rename Navigation to NavHistory

This commit is contained in:
Antonio Scandurra 2022-01-19 15:27:34 +01:00
parent 7c233ed682
commit 18f1040c85
5 changed files with 44 additions and 44 deletions

View file

@ -17,7 +17,7 @@ use postage::watch;
use project::{Project, ProjectPath, WorktreeId};
use std::{cmp::Ordering, mem, ops::Range, rc::Rc, sync::Arc};
use util::TryFutureExt;
use workspace::{Navigation, Workspace};
use workspace::{NavHistory, Workspace};
action!(Deploy);
action!(OpenExcerpts);
@ -522,7 +522,7 @@ impl workspace::Item for ProjectDiagnostics {
fn build_view(
handle: ModelHandle<Self>,
workspace: &Workspace,
_: Rc<Navigation>,
_: Rc<NavHistory>,
cx: &mut ViewContext<Self::View>,
) -> Self::View {
ProjectDiagnosticsEditor::new(handle, workspace.weak_handle(), workspace.settings(), cx)

View file

@ -49,7 +49,7 @@ use sum_tree::Bias;
use text::rope::TextDimension;
use theme::{DiagnosticStyle, EditorStyle};
use util::post_inc;
use workspace::{Navigation, PathOpener, Workspace};
use workspace::{NavHistory, PathOpener, Workspace};
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
const MAX_LINE_LEN: usize = 1024;
@ -379,7 +379,7 @@ pub struct Editor {
mode: EditorMode,
placeholder_text: Option<Arc<str>>,
highlighted_rows: Option<Range<u32>>,
navigation: Option<Rc<Navigation>>,
nav_history: Option<Rc<NavHistory>>,
}
pub struct EditorSnapshot {
@ -465,7 +465,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.nav_history = self.nav_history.clone();
clone
}
@ -515,7 +515,7 @@ impl Editor {
mode: EditorMode::Full,
placeholder_text: None,
highlighted_rows: None,
navigation: None,
nav_history: None,
};
let selection = Selection {
id: post_inc(&mut this.next_selection_id),
@ -860,7 +860,7 @@ impl Editor {
}
}
self.push_to_navigation_history(newest_selection.head(), Some(end.to_point(&buffer)), cx);
self.push_to_nav_history(newest_selection.head(), Some(end.to_point(&buffer)), cx);
let selection = Selection {
id: post_inc(&mut self.next_selection_id),
@ -2455,13 +2455,13 @@ impl Editor {
self.update_selections(vec![selection], Some(Autoscroll::Fit), cx);
}
fn push_to_navigation_history(
fn push_to_nav_history(
&self,
position: Anchor,
new_position: Option<Point>,
cx: &mut ViewContext<Self>,
) {
if let Some(navigation) = &self.navigation {
if let Some(nav_history) = &self.nav_history {
let buffer = self.buffer.read(cx).read(cx);
let offset = position.to_offset(&buffer);
let point = position.to_point(&buffer);
@ -2474,7 +2474,7 @@ impl Editor {
}
}
navigation.push(
nav_history.push(
Some(NavigationData {
anchor: position,
offset,
@ -3330,7 +3330,7 @@ impl Editor {
.max_by_key(|s| s.id)
.map(|s| s.head().to_point(&buffer));
if new_cursor_position.is_some() {
self.push_to_navigation_history(old_cursor_position, new_cursor_position, cx);
self.push_to_nav_history(old_cursor_position, new_cursor_position, cx);
}
}
@ -4174,22 +4174,22 @@ mod tests {
fn test_navigation_history(cx: &mut gpui::MutableAppContext) {
cx.add_window(Default::default(), |cx| {
use workspace::ItemView;
let navigation = Rc::new(workspace::Navigation::default());
let nav_history = Rc::new(workspace::NavHistory::default());
let settings = EditorSettings::test(&cx);
let buffer = MultiBuffer::build_simple(&sample_text(30, 5, 'a'), cx);
let mut editor = build_editor(buffer.clone(), settings, cx);
editor.navigation = Some(navigation.clone());
editor.nav_history = Some(nav_history.clone());
// Move the cursor a small distance.
// Nothing is added to the navigation history.
editor.select_display_ranges(&[DisplayPoint::new(1, 0)..DisplayPoint::new(1, 0)], cx);
editor.select_display_ranges(&[DisplayPoint::new(3, 0)..DisplayPoint::new(3, 0)], cx);
assert!(navigation.pop_backward().is_none());
assert!(nav_history.pop_backward().is_none());
// Move the cursor a large distance.
// The history can jump back to the previous position.
editor.select_display_ranges(&[DisplayPoint::new(13, 0)..DisplayPoint::new(13, 3)], cx);
let nav_entry = navigation.pop_backward().unwrap();
let nav_entry = nav_history.pop_backward().unwrap();
editor.navigate(nav_entry.data.unwrap(), cx);
assert_eq!(nav_entry.item_view.id(), cx.view_id());
assert_eq!(
@ -4205,7 +4205,7 @@ mod tests {
editor.selected_display_ranges(cx),
&[DisplayPoint::new(5, 0)..DisplayPoint::new(5, 0)]
);
assert!(navigation.pop_backward().is_none());
assert!(nav_history.pop_backward().is_none());
// Move the cursor a large distance via the mouse.
// The history can jump back to the previous position.
@ -4215,7 +4215,7 @@ mod tests {
editor.selected_display_ranges(cx),
&[DisplayPoint::new(15, 0)..DisplayPoint::new(15, 0)]
);
let nav_entry = navigation.pop_backward().unwrap();
let nav_entry = nav_history.pop_backward().unwrap();
editor.navigate(nav_entry.data.unwrap(), cx);
assert_eq!(nav_entry.item_view.id(), cx.view_id());
assert_eq!(

View file

@ -13,7 +13,7 @@ use std::rc::Rc;
use text::{Point, Selection};
use util::TryFutureExt;
use workspace::{
ItemHandle, ItemView, ItemViewHandle, Navigation, PathOpener, Settings, StatusItemView,
ItemHandle, ItemView, ItemViewHandle, NavHistory, PathOpener, Settings, StatusItemView,
WeakItemHandle, Workspace,
};
@ -46,7 +46,7 @@ impl ItemHandle for BufferItemHandle {
&self,
window_id: usize,
workspace: &Workspace,
navigation: Rc<Navigation>,
nav_history: Rc<NavHistory>,
cx: &mut MutableAppContext,
) -> Box<dyn ItemViewHandle> {
let buffer = cx.add_model(|cx| MultiBuffer::singleton(self.0.clone(), cx));
@ -57,7 +57,7 @@ impl ItemHandle for BufferItemHandle {
crate::settings_builder(weak_buffer, workspace.settings()),
cx,
);
editor.navigation = Some(navigation);
editor.nav_history = Some(nav_history);
editor
}))
}
@ -115,9 +115,9 @@ impl ItemView for Editor {
};
drop(buffer);
let navigation = self.navigation.take();
let nav_history = self.nav_history.take();
self.select_ranges([offset..offset], Some(Autoscroll::Fit), cx);
self.navigation = navigation;
self.nav_history = nav_history;
}
}
@ -150,7 +150,7 @@ impl ItemView for Editor {
fn deactivated(&mut self, cx: &mut ViewContext<Self>) {
if let Some(selection) = self.newest_selection_internal() {
self.push_to_navigation_history(selection.head(), None, cx);
self.push_to_nav_history(selection.head(), None, cx);
}
}

View file

@ -76,14 +76,14 @@ pub struct Pane {
item_views: Vec<(usize, Box<dyn ItemViewHandle>)>,
active_item_index: usize,
settings: watch::Receiver<Settings>,
navigation: Rc<Navigation>,
nav_history: Rc<NavHistory>,
}
#[derive(Default)]
pub struct Navigation(RefCell<NavigationHistory>);
pub struct NavHistory(RefCell<NavHistoryState>);
#[derive(Default)]
struct NavigationHistory {
struct NavHistoryState {
mode: NavigationMode,
backward_stack: VecDeque<NavigationEntry>,
forward_stack: VecDeque<NavigationEntry>,
@ -114,7 +114,7 @@ impl Pane {
item_views: Vec::new(),
active_item_index: 0,
settings,
navigation: Default::default(),
nav_history: Default::default(),
}
}
@ -148,7 +148,7 @@ impl Pane {
) -> Task<()> {
let to_load = pane.update(cx, |pane, cx| {
// Retrieve the weak item handle from the history.
let entry = pane.navigation.pop(mode)?;
let entry = pane.nav_history.pop(mode)?;
// If the item is still present in this pane, then activate it.
if let Some(index) = entry
@ -157,9 +157,9 @@ impl Pane {
.and_then(|v| pane.index_for_item_view(v.as_ref()))
{
if let Some(item_view) = pane.active_item() {
pane.navigation.set_mode(mode);
pane.nav_history.set_mode(mode);
item_view.deactivated(cx);
pane.navigation.set_mode(NavigationMode::Normal);
pane.nav_history.set_mode(NavigationMode::Normal);
}
pane.active_item_index = index;
@ -173,7 +173,7 @@ impl Pane {
// If the item is no longer present in this pane, then retrieve its
// project path in order to reopen it.
else {
pane.navigation
pane.nav_history
.0
.borrow_mut()
.paths_by_item
@ -192,9 +192,9 @@ impl Pane {
if let Some(pane) = cx.read(|cx| pane.upgrade(cx)) {
if let Some(item) = item.log_err() {
workspace.update(&mut cx, |workspace, cx| {
pane.update(cx, |p, _| p.navigation.set_mode(mode));
pane.update(cx, |p, _| p.nav_history.set_mode(mode));
let item_view = workspace.open_item_in_pane(item, &pane, cx);
pane.update(cx, |p, _| p.navigation.set_mode(NavigationMode::Normal));
pane.update(cx, |p, _| p.nav_history.set_mode(NavigationMode::Normal));
if let Some(data) = entry.data {
item_view.navigate(data, cx);
@ -232,7 +232,7 @@ impl Pane {
}
let item_view =
item_handle.add_view(cx.window_id(), workspace, self.navigation.clone(), cx);
item_handle.add_view(cx.window_id(), workspace, self.nav_history.clone(), cx);
self.add_item_view(item_view.boxed_clone(), cx);
item_view
}
@ -322,11 +322,11 @@ impl Pane {
item_view.deactivated(cx);
}
let mut navigation = self.navigation.0.borrow_mut();
let mut nav_history = self.nav_history.0.borrow_mut();
if let Some(path) = item_view.project_path(cx) {
navigation.paths_by_item.insert(item_view.id(), path);
nav_history.paths_by_item.insert(item_view.id(), path);
} else {
navigation.paths_by_item.remove(&item_view.id());
nav_history.paths_by_item.remove(&item_view.id());
}
item_ix += 1;
@ -536,7 +536,7 @@ impl View for Pane {
}
}
impl Navigation {
impl NavHistory {
pub fn pop_backward(&self) -> Option<NavigationEntry> {
self.0.borrow_mut().backward_stack.pop_back()
}

View file

@ -137,7 +137,7 @@ pub trait Item: Entity + Sized {
fn build_view(
handle: ModelHandle<Self>,
workspace: &Workspace,
navigation: Rc<Navigation>,
nav_history: Rc<NavHistory>,
cx: &mut ViewContext<Self::View>,
) -> Self::View;
@ -190,7 +190,7 @@ pub trait ItemHandle: Send + Sync {
&self,
window_id: usize,
workspace: &Workspace,
navigation: Rc<Navigation>,
nav_history: Rc<NavHistory>,
cx: &mut MutableAppContext,
) -> Box<dyn ItemViewHandle>;
fn boxed_clone(&self) -> Box<dyn ItemHandle>;
@ -242,11 +242,11 @@ impl<T: Item> ItemHandle for ModelHandle<T> {
&self,
window_id: usize,
workspace: &Workspace,
navigation: Rc<Navigation>,
nav_history: Rc<NavHistory>,
cx: &mut MutableAppContext,
) -> Box<dyn ItemViewHandle> {
Box::new(cx.add_view(window_id, |cx| {
T::build_view(self.clone(), workspace, navigation, cx)
T::build_view(self.clone(), workspace, nav_history, cx)
}))
}
@ -276,10 +276,10 @@ impl ItemHandle for Box<dyn ItemHandle> {
&self,
window_id: usize,
workspace: &Workspace,
navigation: Rc<Navigation>,
nav_history: Rc<NavHistory>,
cx: &mut MutableAppContext,
) -> Box<dyn ItemViewHandle> {
ItemHandle::add_view(self.as_ref(), window_id, workspace, navigation, cx)
ItemHandle::add_view(self.as_ref(), window_id, workspace, nav_history, cx)
}
fn boxed_clone(&self) -> Box<dyn ItemHandle> {