on master help sign in
Vertical Selection
f160008Cor
helix-term/src/commands.rs+30
@@ -172,6 +172,8 @@ impl Command {
172 extend_char_right, "Extend right",
172 extend_char_right, "Extend right",
173 extend_line_up, "Extend up",
173 extend_line_up, "Extend up",
174 extend_line_down, "Extend down",
174 extend_line_down, "Extend down",
175+ copy_selection_on_next_line, "Copy selection on next line",
176+ copy_selection_on_prev_line, "Copy selection on previous line",
175 move_next_word_start, "Move to beginning of next word",
177 move_next_word_start, "Move to beginning of next word",
176 move_prev_word_start, "Move to beginning of previous word",
178 move_prev_word_start, "Move to beginning of previous word",
177 move_next_word_end, "Move to end of next word",
179 move_next_word_end, "Move to end of next word",
@@ -958,6 +960,34 @@ fn extend_char_right(cx: &mut Context) {
958 doc.set_selection(view.id, selection);
960 doc.set_selection(view.id, selection);
959}
961}
960
962
963+fn copy_selection_on_prev_line(cx: &mut Context) {
964+ let count = cx.count();
965+ let (view, doc) = current!(cx.editor);
966+ let text = doc.text().slice(..);
967+ let old_selection = doc.selection(view.id).clone();
968+ let mut ranges: SmallVec<_> = old_selection.ranges().into();
969+ for r in old_selection.iter() {
970+ ranges.push(Range::point(
971+ movement::move_vertically(text, *r, Direction::Backward, count, Movement::Extend).head,
972+ ));
973+ }
974+ doc.set_selection(view.id, Selection::new(ranges, old_selection.cursor()));
975+}
976+
977+fn copy_selection_on_next_line(cx: &mut Context) {
978+ let count = cx.count();
979+ let (view, doc) = current!(cx.editor);
980+ let text = doc.text().slice(..);
981+ let old_selection = doc.selection(view.id).clone();
982+ let mut ranges: SmallVec<_> = old_selection.ranges().into();
983+ for r in old_selection.iter() {
984+ ranges.push(Range::point(
985+ movement::move_vertically(text, *r, Direction::Forward, count, Movement::Extend).head,
986+ ));
987+ }
988+ doc.set_selection(view.id, Selection::new(ranges, old_selection.cursor()));
989+}
990+
961fn extend_line_up(cx: &mut Context) {
991fn extend_line_up(cx: &mut Context) {
962 let count = cx.count();
992 let count = cx.count();
963 let (view, doc) = current!(cx.editor);
993 let (view, doc) = current!(cx.editor);
helix-term/src/keymap.rs+4
@@ -387,6 +387,10 @@ impl Default for Keymaps {
387 "c" => change_selection,
387 "c" => change_selection,
388 // TODO: also change delete without yanking
388 // TODO: also change delete without yanking
389
389
390+ "C" => copy_selection_on_next_line,
391+ "alt-C" => copy_selection_on_prev_line,
392+
393+
390 "s" => select_regex,
394 "s" => select_regex,
391 "A-s" => split_selection_on_newline,
395 "A-s" => split_selection_on_newline,
392 "S" => split_selection,
396 "S" => split_selection,