Make cursor move to duplicated line when duplicating line up (#41004)

![Screen Recording 2025-10-23 at 14 50
26](https://github.com/user-attachments/assets/3427aa06-faf4-4f76-a604-bfc5af30f8ce)

Closes #40919
Follow-up of #39610

Release Notes:
- When duplicating line up, fixed cursor to move to the duplicated line
This commit is contained in:
Tom Planche
2025-10-24 02:20:16 +03:00
committed by GitHub
parent af0d2ad491
commit 79eff1fe05
2 changed files with 53 additions and 7 deletions
+5 -5
View File
@@ -5646,8 +5646,8 @@ fn test_duplicate_line(cx: &mut TestAppContext) {
);
});
// With `move_upwards` the selections stay in place, except for
// the lines inserted above them
// With `duplicate_line_up` the selections move to the duplicated lines,
// which are inserted above the original lines
let editor = cx.add_window(|window, cx| {
let buffer = MultiBuffer::build_simple("abc\ndef\nghi\n", cx);
build_editor(buffer, window, cx)
@@ -5669,7 +5669,7 @@ fn test_duplicate_line(cx: &mut TestAppContext) {
DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 1),
DisplayPoint::new(DisplayRow(0), 2)..DisplayPoint::new(DisplayRow(0), 2),
DisplayPoint::new(DisplayRow(2), 0)..DisplayPoint::new(DisplayRow(2), 0),
DisplayPoint::new(DisplayRow(6), 0)..DisplayPoint::new(DisplayRow(6), 0),
DisplayPoint::new(DisplayRow(5), 0)..DisplayPoint::new(DisplayRow(5), 0),
]
);
});
@@ -26888,8 +26888,8 @@ fn test_duplicate_line_up_on_last_line_without_newline(cx: &mut TestAppContext)
assert_eq!(
editor.selections.display_ranges(cx),
vec![DisplayPoint::new(DisplayRow(1), 0)..DisplayPoint::new(DisplayRow(1), 0)],
"Selection should remain on the original line"
vec![DisplayPoint::new(DisplayRow(0), 0)..DisplayPoint::new(DisplayRow(0), 0)],
"Selection should move to the duplicated line"
);
})
.unwrap();