Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

editor: Avoid autoscroll in SplitSelectionIntoLines (#49399)

it-education-md465e2b5ffd9a
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index 0c269930483..efc3cddcc85 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::<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);
});
}
diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs
index 2898954b75a..38abff942ac 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, |_| {});