From 16a4c59be0fc3e683587b6896c9ce568ddb823dd Mon Sep 17 00:00:00 2001 From: Congyu <52687642+Congyuwang@users.noreply.github.com> Date: Thu, 18 Jul 2024 04:19:35 +0800 Subject: [PATCH] Fix right clicks changing vim mode (#14626) Release Notes: - Fixed right clicks changing vim mode (#14625). before: https://github.com/user-attachments/assets/97f4c971-6b59-412d-844a-23e0bc4289aa after: https://github.com/user-attachments/assets/3fc9adf3-2572-428d-8674-b3c8317e457e --- crates/editor/src/mouse_context_menu.rs | 10 +++--- crates/editor/src/selections_collection.rs | 40 ---------------------- 2 files changed, 6 insertions(+), 44 deletions(-) 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;