aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorCor2021-07-17 12:09:46 +0000
committerBlaž Hrastnik2021-08-05 08:04:26 +0000
commitf160008add247567f8e6704b54e9cd87fbe72983 (patch)
tree751264f3dd299fe7cc9a18adb80d0856e23d2b9a /helix-term/src
parentc9cbc344fc28dee5a0a5d3a7662c5c223067ab23 (diff)
Vertical Selection
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs30
-rw-r--r--helix-term/src/keymap.rs4
2 files changed, 34 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index ceb01ef3..d9c26c4a 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -172,6 +172,8 @@ impl Command {
extend_char_right, "Extend right",
extend_line_up, "Extend up",
extend_line_down, "Extend down",
+ copy_selection_on_next_line, "Copy selection on next line",
+ copy_selection_on_prev_line, "Copy selection on previous line",
move_next_word_start, "Move to beginning of next word",
move_prev_word_start, "Move to beginning of previous word",
move_next_word_end, "Move to end of next word",
@@ -958,6 +960,34 @@ fn extend_char_right(cx: &mut Context) {
doc.set_selection(view.id, selection);
}
+fn copy_selection_on_prev_line(cx: &mut Context) {
+ let count = cx.count();
+ let (view, doc) = current!(cx.editor);
+ let text = doc.text().slice(..);
+ let old_selection = doc.selection(view.id).clone();
+ let mut ranges: SmallVec<_> = old_selection.ranges().into();
+ for r in old_selection.iter() {
+ ranges.push(Range::point(
+ movement::move_vertically(text, *r, Direction::Backward, count, Movement::Extend).head,
+ ));
+ }
+ doc.set_selection(view.id, Selection::new(ranges, old_selection.cursor()));
+}
+
+fn copy_selection_on_next_line(cx: &mut Context) {
+ let count = cx.count();
+ let (view, doc) = current!(cx.editor);
+ let text = doc.text().slice(..);
+ let old_selection = doc.selection(view.id).clone();
+ let mut ranges: SmallVec<_> = old_selection.ranges().into();
+ for r in old_selection.iter() {
+ ranges.push(Range::point(
+ movement::move_vertically(text, *r, Direction::Forward, count, Movement::Extend).head,
+ ));
+ }
+ doc.set_selection(view.id, Selection::new(ranges, old_selection.cursor()));
+}
+
fn extend_line_up(cx: &mut Context) {
let count = cx.count();
let (view, doc) = current!(cx.editor);
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index cba3b3d0..77a3b8bc 100644
--- a/helix-term/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -387,6 +387,10 @@ impl Default for Keymaps {
"c" => change_selection,
// TODO: also change delete without yanking
+ "C" => copy_selection_on_next_line,
+ "alt-C" => copy_selection_on_prev_line,
+
+
"s" => select_regex,
"A-s" => split_selection_on_newline,
"S" => split_selection,