Navigate to previous positions in editors when using navigation history

This commit is contained in:
Max Brunsfeld
2022-01-17 16:01:52 -08:00
parent e43d33cdad
commit 11b7270f68
4 changed files with 107 additions and 66 deletions
+13
View File
@@ -2399,6 +2399,8 @@ impl Editor {
return;
}
self.push_to_navigation_history(cx);
let selection = Selection {
id: post_inc(&mut self.next_selection_id),
start: 0,
@@ -2421,6 +2423,8 @@ impl Editor {
return;
}
self.push_to_navigation_history(cx);
let cursor = self.buffer.read(cx).read(cx).len();
let selection = Selection {
id: post_inc(&mut self.next_selection_id),
@@ -2432,6 +2436,15 @@ impl Editor {
self.update_selections(vec![selection], Some(Autoscroll::Fit), cx);
}
fn push_to_navigation_history(&self, cx: &mut ViewContext<Self>) {
if let Some(navigation) = &self.navigation {
if let Some(last_selection) = self.selections.iter().max_by_key(|s| s.id) {
let cursor = last_selection.head();
navigation.push(Some(cursor), cx);
}
}
}
pub fn select_to_end(&mut self, _: &SelectToEnd, cx: &mut ViewContext<Self>) {
let mut selection = self.local_selections::<usize>(cx).first().unwrap().clone();
selection.set_head(self.buffer.read(cx).read(cx).len());