diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 0c2699304830482ba5a9ac23d561d9ea9d8c5b61..efc3cddcc8549df6d832e726c77f2dda600adaa4 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -15397,7 +15397,7 @@ impl Editor { .into_iter() .map(|selection| selection.start..selection.end) .collect::>(); - self.unfold_ranges(&selections, true, true, cx); + self.unfold_ranges(&selections, true, false, cx); let mut new_selection_ranges = Vec::new(); { @@ -15439,7 +15439,7 @@ impl Editor { } } } - self.change_selections(Default::default(), window, cx, |s| { + self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { s.select_ranges(new_selection_ranges); }); } diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index 2898954b75a97c7d7d0a922eae8e71c8b598a7d5..38abff942acf8717000090a90654f1117ba5005d 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -8538,6 +8538,26 @@ async fn test_split_selection_into_lines(cx: &mut TestAppContext) { ); } +#[gpui::test] +async fn test_split_selection_into_lines_does_not_scroll(cx: &mut TestAppContext) { + init_test(cx, |_| {}); + let mut cx = EditorTestContext::new(cx).await; + + let large_body = "\nline".repeat(300); + cx.set_state(&format!("«ˇstart{large_body}\nend»")); + let initial_scroll_position = cx.update_editor(|editor, _, cx| editor.scroll_position(cx)); + + cx.update_editor(|editor, window, cx| { + editor.split_selection_into_lines(&Default::default(), window, cx); + }); + + let scroll_position_after_split = cx.update_editor(|editor, _, cx| editor.scroll_position(cx)); + assert_eq!( + initial_scroll_position, scroll_position_after_split, + "Scroll position should not change after splitting selection into lines" + ); +} + #[gpui::test] async fn test_split_selection_into_lines_interacting_with_creases(cx: &mut TestAppContext) { init_test(cx, |_| {});