Improve bindings to better match VS-Code (#8584)

Release Notes:

- Changed default keybindings in the VS Code keymap so that
`alt-[up|down]` now move lines up/down and`alt-shift-[up|down]`
duplicate lines up/down. Previous bindings for selecting larger/smaller
syntax nodes are now bound to `ctrl-shift-[left|right]`.
([#4652](https://github.com/zed-industries/zed/issues/4652))([#7151](https://github.com/zed-industries/zed/issues/7151))

---------

Co-authored-by: Thorsten Ball <mrnugget@gmail.com>
This commit is contained in:
Edvard Høiby
2024-03-06 11:16:14 -08:00
committed by GitHub
co-authored by Thorsten Ball
parent 850ddddcac
commit 8352f39ff9
6 changed files with 87 additions and 14 deletions
+9 -3
View File
@@ -5032,7 +5032,7 @@ impl Editor {
});
}
pub fn duplicate_line(&mut self, _: &DuplicateLine, cx: &mut ViewContext<Self>) {
pub fn duplicate_line(&mut self, action: &DuplicateLine, cx: &mut ViewContext<Self>) {
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
let buffer = &display_map.buffer_snapshot;
let selections = self.selections.all::<Point>(cx);
@@ -5053,14 +5053,20 @@ impl Editor {
}
}
// Copy the text from the selected row region and splice it at the start of the region.
// Copy the text from the selected row region and splice it either at the start
// or end of the region.
let start = Point::new(rows.start, 0);
let end = Point::new(rows.end - 1, buffer.line_len(rows.end - 1));
let text = buffer
.text_for_range(start..end)
.chain(Some("\n"))
.collect::<String>();
edits.push((start..start, text));
let insert_location = if action.move_upwards {
Point::new(rows.end, 0)
} else {
start
};
edits.push((insert_location..insert_location, text));
}
self.transact(cx, |this, cx| {