diff --git a/crates/editor/src/mouse_context_menu.rs b/crates/editor/src/mouse_context_menu.rs index 82e8878b31..1ad8040624 100644 --- a/crates/editor/src/mouse_context_menu.rs +++ b/crates/editor/src/mouse_context_menu.rs @@ -74,10 +74,10 @@ pub fn deploy_context_menu( let context_menu = if let Some(custom) = editor.custom_context_menu.take() { let menu = custom(editor, point, cx); editor.custom_context_menu = Some(custom); - if menu.is_none() { + let Some(menu) = menu else { return; - } - menu.unwrap() + }; + menu } else { // Don't show the context menu if there isn't a project associated with this editor if editor.project.is_none() { @@ -85,11 +85,13 @@ pub fn deploy_context_menu( } let display_map = editor.selections.display_map(cx); + let buffer = &editor.snapshot(cx).buffer_snapshot; + let anchor = buffer.anchor_before(point.to_point(&display_map)); if !display_ranges(&display_map, &editor.selections).any(|r| r.contains(&point)) { // Move the cursor to the clicked location so that dispatched actions make sense editor.change_selections(None, cx, |s| { s.clear_disjoint(); - s.set_pending_display_range(point..point, SelectMode::Character); + s.set_pending_anchor_range(anchor..anchor, SelectMode::Character); }); } diff --git a/crates/editor/src/selections_collection.rs b/crates/editor/src/selections_collection.rs index 7a448f0b6c..3c2c428377 100644 --- a/crates/editor/src/selections_collection.rs +++ b/crates/editor/src/selections_collection.rs @@ -426,46 +426,6 @@ impl<'a> MutableSelectionsCollection<'a> { self.selections_changed = true; } - pub(crate) fn set_pending_display_range( - &mut self, - range: Range, - mode: SelectMode, - ) { - let (start, end, reversed) = { - let display_map = self.display_map(); - let buffer = self.buffer(); - let mut start = range.start; - let mut end = range.end; - let reversed = if start > end { - mem::swap(&mut start, &mut end); - true - } else { - false - }; - - let end_bias = if end > start { Bias::Left } else { Bias::Right }; - ( - buffer.anchor_before(start.to_point(&display_map)), - buffer.anchor_at(end.to_point(&display_map), end_bias), - reversed, - ) - }; - - let new_pending = PendingSelection { - selection: Selection { - id: post_inc(&mut self.collection.next_selection_id), - start, - end, - reversed, - goal: SelectionGoal::None, - }, - mode, - }; - - self.collection.pending = Some(new_pending); - self.selections_changed = true; - } - pub(crate) fn set_pending(&mut self, selection: Selection, mode: SelectMode) { self.collection.pending = Some(PendingSelection { selection, mode }); self.selections_changed = true;