Merge pull request #667 from zed-industries/fix-duplicate-nav-entries

Fix duplicate nav entries
This commit is contained in:
Max Brunsfeld 2022-03-23 11:49:00 -07:00 committed by GitHub
commit cbd4ef2ec5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 110 additions and 47 deletions

View file

@ -1393,8 +1393,6 @@ impl Editor {
}
}
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),
start,
@ -5111,7 +5109,7 @@ impl Editor {
cx.notify();
}
fn transact(
pub fn transact(
&mut self,
cx: &mut ViewContext<Self>,
update: impl FnOnce(&mut Self, &mut ViewContext<Self>),
@ -6328,6 +6326,7 @@ mod tests {
editor.selected_display_ranges(cx),
&[DisplayPoint::new(3, 0)..DisplayPoint::new(3, 0)]
);
assert!(nav_history.borrow_mut().pop_backward().is_none());
// Move the cursor a small distance via the mouse.
// Nothing is added to the navigation history.
@ -6354,6 +6353,7 @@ mod tests {
editor.selected_display_ranges(cx),
&[DisplayPoint::new(5, 0)..DisplayPoint::new(5, 0)]
);
assert!(nav_history.borrow_mut().pop_backward().is_none());
editor
});

View file

@ -242,7 +242,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) {
@ -250,11 +250,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
}
}