From dad33f7cc2f51d8c7f53fd12ef2a496cfd837ee2 Mon Sep 17 00:00:00 2001 From: Austin Merrick Date: Thu, 10 Apr 2025 12:53:00 -0700 Subject: [PATCH] Fix code action selection bug while using vim visual mode (#27817) ## Problem Code actions do not handle vim line mode correctly. See this video where `Extract to function` doesn't extract both selected lines: https://github.com/user-attachments/assets/8fa0fb28-0403-44f6-9e55-a59b6713dffd ## Solution Use `selections.newest_adjusted` instead of `selections.newest_anchor` so code actions consider the full selection. Correct behavior: https://github.com/user-attachments/assets/174d5a34-3873-4d20-b67d-103edec4cdbe --- Release Notes: - vim: Fixed code actions in visual line mode --- crates/editor/src/editor.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 51435aefe3..cd55b55441 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -5172,13 +5172,16 @@ impl Editor { } fn refresh_code_actions(&mut self, window: &mut Window, cx: &mut Context) -> Option<()> { - let buffer = self.buffer.read(cx); let newest_selection = self.selections.newest_anchor().clone(); + let newest_selection_adjusted = self.selections.newest_adjusted(cx).clone(); + let buffer = self.buffer.read(cx); if newest_selection.head().diff_base_anchor.is_some() { return None; } - let (start_buffer, start) = buffer.text_anchor_for_position(newest_selection.start, cx)?; - let (end_buffer, end) = buffer.text_anchor_for_position(newest_selection.end, cx)?; + let (start_buffer, start) = + buffer.text_anchor_for_position(newest_selection_adjusted.start, cx)?; + let (end_buffer, end) = + buffer.text_anchor_for_position(newest_selection_adjusted.end, cx)?; if start_buffer != end_buffer { return None; }