This commit is contained in:
Antonio Scandurra
2022-03-23 19:05:46 +01:00
parent 255a8c5d14
commit 5cd94b5b92
5 changed files with 61 additions and 44 deletions
+13 -5
View File
@@ -241,7 +241,7 @@ fn deserialize_selection(
}
impl Item for Editor {
fn navigate(&mut self, data: Box<dyn std::any::Any>, cx: &mut ViewContext<Self>) {
fn navigate(&mut self, data: Box<dyn std::any::Any>, cx: &mut ViewContext<Self>) -> bool {
if let Some(data) = data.downcast_ref::<NavigationData>() {
let buffer = self.buffer.read(cx).read(cx);
let offset = if buffer.can_resolve(&data.anchor) {
@@ -249,11 +249,19 @@ impl Item for Editor {
} else {
buffer.clip_offset(data.offset, Bias::Left)
};
let newest_selection = self.newest_selection_with_snapshot::<usize>(&buffer);
drop(buffer);
let nav_history = self.nav_history.take();
self.select_ranges([offset..offset], Some(Autoscroll::Fit), cx);
self.nav_history = nav_history;
if newest_selection.head() == offset {
false
} else {
let nav_history = self.nav_history.take();
self.select_ranges([offset..offset], Some(Autoscroll::Fit), cx);
self.nav_history = nav_history;
true
}
} else {
false
}
}