diff --git a/crates/vim/src/helix.rs b/crates/vim/src/helix.rs index 4a1ab02f1a86e660399b58ccf0323a2b36a64970..526519fd13447e24ffc94fa5ee20c73ff288e239 100644 --- a/crates/vim/src/helix.rs +++ b/crates/vim/src/helix.rs @@ -1758,4 +1758,81 @@ mod test { assert_eq!(vim_mode, Some(Mode::HelixNormal)); }); } + + #[gpui::test] + async fn test_scroll_with_selection(cx: &mut gpui::TestAppContext) { + let mut cx = VimTestContext::new(cx, true).await; + cx.enable_helix(); + + // Start with a selection + cx.set_state( + indoc! {" + «lineˇ» one + line two + line three + line four + line five"}, + Mode::HelixNormal, + ); + + // Scroll down, selection should collapse + cx.simulate_keystrokes("ctrl-d"); + cx.assert_state( + indoc! {" + line one + line two + line three + line four + line fiveˇ"}, + Mode::HelixNormal, + ); + + // Make a new selection + cx.simulate_keystroke("b"); + cx.assert_state( + indoc! {" + line one + line two + line three + line four + line «ˇfive»"}, + Mode::HelixNormal, + ); + + // And scroll up, once again collapsing the selection. + cx.simulate_keystroke("ctrl-u"); + cx.assert_state( + indoc! {" + line one + line two + line three + line ˇfour + line five"}, + Mode::HelixNormal, + ); + + // Enter select mode + cx.simulate_keystroke("v"); + cx.assert_state( + indoc! {" + line one + line two + line three + line «fˇ»our + line five"}, + Mode::HelixSelect, + ); + + // And now the selection should be kept/expanded. + cx.simulate_keystroke("ctrl-d"); + cx.assert_state( + indoc! {" + line one + line two + line three + line «four + line fiveˇ»"}, + Mode::HelixSelect, + ); + } } diff --git a/crates/vim/src/normal/scroll.rs b/crates/vim/src/normal/scroll.rs index 73209c88735a59bb2dc5c2b73bb3ba0c7d03dd56..6360dc1ecd1ed1f39059e0be54253240c486b698 100644 --- a/crates/vim/src/normal/scroll.rs +++ b/crates/vim/src/normal/scroll.rs @@ -1,4 +1,4 @@ -use crate::Vim; +use crate::{Vim, state::Mode}; use editor::{ DisplayPoint, Editor, EditorSettings, SelectionEffects, display_map::{DisplayRow, ToDisplayPoint}, @@ -95,16 +95,18 @@ impl Vim { by: fn(c: Option) -> ScrollAmount, ) { let amount = by(Vim::take_count(cx).map(|c| c as f32)); + let mode = self.mode; Vim::take_forced_motion(cx); self.exit_temporary_normal(window, cx); self.update_editor(cx, |_, editor, cx| { - scroll_editor(editor, move_cursor, amount, window, cx) + scroll_editor(editor, mode, move_cursor, amount, window, cx) }); } } fn scroll_editor( editor: &mut Editor, + mode: Mode, preserve_cursor_position: bool, amount: ScrollAmount, window: &mut Window, @@ -255,7 +257,7 @@ fn scroll_editor( _ => selection.goal, }; - if selection.is_empty() { + if selection.is_empty() || !mode.is_visual() { selection.collapse_to(new_head, goal) } else { selection.set_head(new_head, goal)