Merge pull request #886 from zed-industries/fix-delete-to-beginning-of-line

Delete selected text when deleting to beginning of line, regardless of selection direction
This commit is contained in:
Antonio Scandurra 2022-04-22 15:55:51 +02:00 committed by GitHub
commit 1dcaec7fb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View file

@ -26,6 +26,7 @@
"bindings": {
"escape": "editor::Cancel",
"backspace": "editor::Backspace",
"shift-backspace": "editor::Backspace",
"ctrl-h": "editor::Backspace",
"delete": "editor::Delete",
"ctrl-d": "editor::Delete",

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