editor: Avoid autoscroll in SplitSelectionIntoLines (#49399)

it-education-md created

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:
<img width="2486" height="1299" alt="image"
src="https://github.com/user-attachments/assets/8408a2f1-7dd7-4984-aa89-927d5a588322"
/>


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

Change summary

crates/editor/src/editor.rs       |  4 ++--
crates/editor/src/editor_tests.rs | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)

Detailed changes

crates/editor/src/editor.rs 🔗

@@ -15397,7 +15397,7 @@ impl Editor {
             .into_iter()
             .map(|selection| selection.start..selection.end)
             .collect::<Vec<_>>();
-        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);
         });
     }

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, |_| {});