Delete selected text when deleting to beginning of line

Nathan Sobo created

Change summary

crates/editor/src/editor.rs | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)

Detailed changes

crates/editor/src/editor.rs 🔗

@@ -3791,6 +3791,10 @@ impl Editor {
         cx: &mut ViewContext<Self>,
     ) {
         self.transact(cx, |this, cx| {
+            this.move_selections(cx, |_, selection| {
+                selection.reversed = true;
+            });
+
             this.select_to_beginning_of_line(
                 &SelectToBeginningOfLine {
                     stop_at_soft_wraps: false,
@@ -7430,6 +7434,21 @@ mod tests {
         });
     }
 
+    #[gpui::test]
+    fn test_delete_to_beginning_of_line(cx: &mut gpui::MutableAppContext) {
+        cx.set_global(Settings::test(cx));
+        let (text, ranges) = marked_text_ranges("one [two three] four");
+        let buffer = MultiBuffer::build_simple(&text, cx);
+
+        let (_, editor) = cx.add_window(Default::default(), |cx| build_editor(buffer.clone(), cx));
+
+        editor.update(cx, |editor, cx| {
+            editor.select_ranges(ranges, None, cx);
+            editor.delete_to_beginning_of_line(&DeleteToBeginningOfLine, cx);
+            assert_eq!(editor.text(cx), " four");
+        });
+    }
+
     #[gpui::test]
     fn test_delete_to_word_boundary(cx: &mut gpui::MutableAppContext) {
         cx.set_global(Settings::test(cx));