Add more emacs-inspired bindings

Word-wise movement and columnar selection without reaching for the arrows.
This commit is contained in:
Nathan Sobo 2021-05-29 12:06:52 -06:00
parent f87aa14ebf
commit 081191917c

View file

@ -53,11 +53,21 @@ pub fn init(cx: &mut MutableAppContext) {
"buffer:delete_to_previous_word_boundary",
Some("BufferView"),
),
Binding::new(
"alt-h",
"buffer:delete_to_previous_word_boundary",
Some("BufferView"),
),
Binding::new(
"alt-delete",
"buffer:delete_to_next_word_boundary",
Some("BufferView"),
),
Binding::new(
"alt-d",
"buffer:delete_to_next_word_boundary",
Some("BufferView"),
),
Binding::new(
"cmd-backspace",
"buffer:delete_to_beginning_of_line",
@ -68,6 +78,7 @@ pub fn init(cx: &mut MutableAppContext) {
"buffer:delete_to_end_of_line",
Some("BufferView"),
),
Binding::new("ctrl-k", "buffer:cut_to_end_of_line", Some("BufferView")),
Binding::new("cmd-shift-D", "buffer:duplicate_line", Some("BufferView")),
Binding::new("ctrl-cmd-up", "buffer:move_line_up", Some("BufferView")),
Binding::new("ctrl-cmd-down", "buffer:move_line_down", Some("BufferView")),
@ -89,11 +100,21 @@ pub fn init(cx: &mut MutableAppContext) {
"buffer:move_to_previous_word_boundary",
Some("BufferView"),
),
Binding::new(
"alt-b",
"buffer:move_to_previous_word_boundary",
Some("BufferView"),
),
Binding::new(
"alt-right",
"buffer:move_to_next_word_boundary",
Some("BufferView"),
),
Binding::new(
"alt-f",
"buffer:move_to_next_word_boundary",
Some("BufferView"),
),
Binding::new(
"cmd-left",
"buffer:move_to_beginning_of_line",
@ -113,19 +134,33 @@ pub fn init(cx: &mut MutableAppContext) {
Binding::new("cmd-up", "buffer:move_to_beginning", Some("BufferView")),
Binding::new("cmd-down", "buffer:move_to_end", Some("BufferView")),
Binding::new("shift-up", "buffer:select_up", Some("BufferView")),
Binding::new("ctrl-shift-P", "buffer:select_up", Some("BufferView")),
Binding::new("shift-down", "buffer:select_down", Some("BufferView")),
Binding::new("ctrl-shift-N", "buffer:select_down", Some("BufferView")),
Binding::new("shift-left", "buffer:select_left", Some("BufferView")),
Binding::new("ctrl-shift-B", "buffer:select_left", Some("BufferView")),
Binding::new("shift-right", "buffer:select_right", Some("BufferView")),
Binding::new("ctrl-shift-F", "buffer:select_right", Some("BufferView")),
Binding::new(
"alt-shift-left",
"buffer:select_to_previous_word_boundary",
Some("BufferView"),
),
Binding::new(
"alt-shift-B",
"buffer:select_to_previous_word_boundary",
Some("BufferView"),
),
Binding::new(
"alt-shift-right",
"buffer:select_to_next_word_boundary",
Some("BufferView"),
),
Binding::new(
"alt-shift-F",
"buffer:select_to_next_word_boundary",
Some("BufferView"),
),
Binding::new(
"cmd-shift-left",
"buffer:select_to_beginning_of_line",
@ -166,21 +201,41 @@ pub fn init(cx: &mut MutableAppContext) {
"buffer:add_selection_above",
Some("BufferView"),
),
Binding::new(
"cmd-ctrl-p",
"buffer:add_selection_above",
Some("BufferView"),
),
Binding::new(
"cmd-alt-down",
"buffer:add_selection_below",
Some("BufferView"),
),
Binding::new(
"cmd-ctrl-n",
"buffer:add_selection_below",
Some("BufferView"),
),
Binding::new(
"alt-up",
"buffer:select_larger_syntax_node",
Some("BufferView"),
),
Binding::new(
"ctrl-w",
"buffer:select_larger_syntax_node",
Some("BufferView"),
),
Binding::new(
"alt-down",
"buffer:select_smaller_syntax_node",
Some("BufferView"),
),
Binding::new(
"ctrl-shift-W",
"buffer:select_smaller_syntax_node",
Some("BufferView"),
),
Binding::new(
"ctrl-m",
"buffer:move_to_enclosing_bracket",
@ -221,6 +276,7 @@ pub fn init(cx: &mut MutableAppContext) {
"buffer:delete_to_end_of_line",
Editor::delete_to_end_of_line,
);
cx.add_action("buffer:cut_to_end_of_line", Editor::cut_to_end_of_line);
cx.add_action("buffer:duplicate_line", Editor::duplicate_line);
cx.add_action("buffer:move_line_up", Editor::move_line_up);
cx.add_action("buffer:move_line_down", Editor::move_line_down);
@ -1558,6 +1614,13 @@ impl Editor {
self.end_transaction(cx);
}
pub fn cut_to_end_of_line(&mut self, _: &(), cx: &mut ViewContext<Self>) {
self.start_transaction(cx);
self.select_to_end_of_line(&(), cx);
self.cut(&(), cx);
self.end_transaction(cx);
}
pub fn move_to_beginning(&mut self, _: &(), cx: &mut ViewContext<Self>) {
let buffer = self.buffer.read(cx);
let cursor = buffer.anchor_before(Point::new(0, 0));