From 6d66ff1d953f8150738daa2aea9e6e9519e762e0 Mon Sep 17 00:00:00 2001 From: thebasilisk <101214144+thebasilisk@users.noreply.github.com> Date: Tue, 3 Jun 2025 00:15:21 -0400 Subject: [PATCH] Add Helix implementation for `Motion::FindForward` and `Motion::FindBackward` (#31547) Closes #30462 Release Notes: - Added text selection for "vim::PushFindForward" and "vim::PushFindBackward" keybinds in helix mode --- crates/vim/src/helix.rs | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/crates/vim/src/helix.rs b/crates/vim/src/helix.rs index 5977ccd106095d1fdd06d9f506e2c11d0ea4a0e7..2e7c371d359d114717fda5c878b553f3c9b3be77 100644 --- a/crates/vim/src/helix.rs +++ b/crates/vim/src/helix.rs @@ -235,6 +235,60 @@ impl Vim { found }) } + Motion::FindForward { .. } => { + self.update_editor(window, cx, |_, editor, window, cx| { + let text_layout_details = editor.text_layout_details(window); + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { + s.move_with(|map, selection| { + let goal = selection.goal; + let cursor = if selection.is_empty() || selection.reversed { + selection.head() + } else { + movement::left(map, selection.head()) + }; + + let (point, goal) = motion + .move_point( + map, + cursor, + selection.goal, + times, + &text_layout_details, + ) + .unwrap_or((cursor, goal)); + selection.set_tail(selection.head(), goal); + selection.set_head(movement::right(map, point), goal); + }) + }); + }); + } + Motion::FindBackward { .. } => { + self.update_editor(window, cx, |_, editor, window, cx| { + let text_layout_details = editor.text_layout_details(window); + editor.change_selections(Some(Autoscroll::fit()), window, cx, |s| { + s.move_with(|map, selection| { + let goal = selection.goal; + let cursor = if selection.is_empty() || selection.reversed { + selection.head() + } else { + movement::left(map, selection.head()) + }; + + let (point, goal) = motion + .move_point( + map, + cursor, + selection.goal, + times, + &text_layout_details, + ) + .unwrap_or((cursor, goal)); + selection.set_tail(selection.head(), goal); + selection.set_head(point, goal); + }) + }); + }); + } _ => self.helix_move_and_collapse(motion, times, window, cx), } }