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.

Unify behavior of delete/cut to line boundary actions (#59627)

Joseph T. Lyonsaf3f79076274
diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs
index f8d98a2b066..6b43dff2cc9 100644
--- a/crates/editor/src/editor_tests.rs
+++ b/crates/editor/src/editor_tests.rs
@@ -3282,20 +3282,29 @@ async fn test_move_page_up_page_down(cx: &mut TestAppContext) {
}
#[gpui::test]
-async fn test_delete_to_beginning_of_line(cx: &mut TestAppContext) {
+async fn test_delete_to_line_boundary(cx: &mut TestAppContext) {
init_test(cx, |_| {});
let mut cx = EditorTestContext::new(cx).await;
- cx.set_state("one «two threeˇ» four");
- cx.update_editor(|editor, window, cx| {
- editor.delete_to_beginning_of_line(
- &DeleteToBeginningOfLine {
- stop_at_indent: false,
- },
- window,
- cx,
- );
- assert_eq!(editor.text(cx), " four");
- });
+
+ for selection in ["one «two threeˇ» four", "one «ˇtwo three» four"] {
+ cx.set_state(selection);
+ cx.update_editor(|editor, window, cx| {
+ editor.delete_to_beginning_of_line(
+ &DeleteToBeginningOfLine {
+ stop_at_indent: false,
+ },
+ window,
+ cx,
+ );
+ assert_eq!(editor.text(cx), " four");
+ });
+
+ cx.set_state(selection);
+ cx.update_editor(|editor, window, cx| {
+ editor.delete_to_end_of_line(&DeleteToEndOfLine, window, cx);
+ assert_eq!(editor.text(cx), "one ");
+ });
+ }
}
#[gpui::test]
@@ -8968,6 +8977,19 @@ async fn test_cut_line_ends(cx: &mut TestAppContext) {
cx.assert_editor_state(indoc! {"
The quickˇ
fox jumps overˇthe lazy dog"});
+
+ for selection in ["The quick «brownˇ» fox", "The quick «ˇbrown» fox"] {
+ cx.set_state(selection);
+ cx.update_editor(|e, window, cx| {
+ e.cut_to_end_of_line(&CutToEndOfLine::default(), window, cx)
+ });
+ cx.assert_editor_state("The quick ˇ");
+ assert_eq!(
+ cx.read_from_clipboard()
+ .and_then(|item| item.text().as_deref().map(str::to_string)),
+ Some("brown fox".to_string())
+ );
+ }
}
#[gpui::test]
diff --git a/crates/editor/src/input.rs b/crates/editor/src/input.rs
index a9ef778a056..876bb8fa286 100644
--- a/crates/editor/src/input.rs
+++ b/crates/editor/src/input.rs
@@ -1141,6 +1141,12 @@ impl Editor {
return;
}
self.transact(window, cx, |this, window, cx| {
+ this.change_selections(Default::default(), window, cx, |s| {
+ s.move_with(&mut |_, selection| {
+ selection.reversed = false;
+ });
+ });
+
this.select_to_end_of_line(
&SelectToEndOfLine {
stop_at_soft_wraps: false,
@@ -1162,6 +1168,12 @@ impl Editor {
return;
}
self.transact(window, cx, |this, window, cx| {
+ this.change_selections(Default::default(), window, cx, |s| {
+ s.move_with(&mut |_, selection| {
+ selection.reversed = false;
+ });
+ });
+
this.select_to_end_of_line(
&SelectToEndOfLine {
stop_at_soft_wraps: false,