From 465e2b5ffd9ac8553341bd3989ce960b4793f917 Mon Sep 17 00:00:00 2001 From: it-education-md <128720033+it-education-md@users.noreply.github.com> Date: Mon, 2 Mar 2026 17:45:19 -0500 Subject: [PATCH] editor: Avoid autoscroll in SplitSelectionIntoLines (#49399) Closes #48812 ## Summary `editor::SplitSelectionIntoLines` currently triggers autoscroll and can jump to the end of a long file. This PR makes the action explicitly no-scroll. ## What changed - Disabled autoscroll in the `unfold_ranges` call inside `split_selection_into_lines`. - Switched selection update to `SelectionEffects::no_scroll()`. ## Testing - Added `test_split_selection_into_lines_does_not_scroll`. ### Screenshots: - Before: see issue video - After: image Before you mark this PR as ready for review, make sure that you have: - [x] Added a solid test coverage and/or screenshots from doing manual testing - [x] Done a self-review taking into account security and performance aspects - [x] Aligned any UI changes with the [UI checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) Release Notes: - Stop scrolling on `editor::SplitSelectionIntoLines` called in the long files --- crates/editor/src/editor.rs | 4 ++-- crates/editor/src/editor_tests.rs | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) 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, |_| {});