Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Fix text manipulation on line mode selections (#37646)
Dinob65fb0626491
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 37951074d15..fd2299f37df 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -11391,14 +11391,17 @@ impl Editor {let mut edits = Vec::new();let mut selection_adjustment = 0i32;- for selection in self.selections.all::<usize>(cx) {+ for selection in self.selections.all_adjusted(cx) {let selection_is_empty = selection.is_empty();let (start, end) = if selection_is_empty {let (word_range, _) = buffer.surrounding_word(selection.start, false);(word_range.start, word_range.end)} else {- (selection.start, selection.end)+ (+ buffer.point_to_offset(selection.start),+ buffer.point_to_offset(selection.end),+ )};let text = buffer.text_for_range(start..end).collect::<String>();@@ -11409,7 +11412,8 @@ impl Editor {start: (start as i32 - selection_adjustment) as usize,end: ((start + text.len()) as i32 - selection_adjustment) as usize,goal: SelectionGoal::None,- ..selection+ id: selection.id,+ reversed: selection.reversed,});selection_adjustment += old_length - text.len() as i32;diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rsindex 90e488368f9..f4569b43648 100644--- a/crates/editor/src/editor_tests.rs+++ b/crates/editor/src/editor_tests.rs@@ -5363,6 +5363,20 @@ async fn test_manipulate_text(cx: &mut TestAppContext) {cx.assert_editor_state(indoc! {"«HeLlO, wOrLD!ˇ»"});++ // Test selections with `line_mode = true`.+ cx.update_editor(|editor, _window, _cx| editor.selections.line_mode = true);+ cx.set_state(indoc! {"+ «The quick brown+ fox jumps over+ tˇ»he lazy dog+ "});+ cx.update_editor(|e, window, cx| e.convert_to_upper_case(&ConvertToUpperCase, window, cx));+ cx.assert_editor_state(indoc! {"+ «THE QUICK BROWN+ FOX JUMPS OVER+ THE LAZY DOGˇ»+ "});}#[gpui::test]