Delete selected text when deleting to beginning of line

This commit is contained in:
Nathan Sobo 2022-04-21 15:12:18 -06:00
parent 30f2604a8d
commit 8ec2b5e359

View file

@ -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));