From a5be718dc61ffcc7c3d3af10e3f175359c7cc562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Wed, 7 Oct 2020 18:31:04 +0900 Subject: [PATCH] x for line selection --- helix-view/src/commands.rs | 12 ++++++++++++ helix-view/src/keymap.rs | 1 + 2 files changed, 13 insertions(+) diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs index ca1e41c4..f2bc3500 100644 --- a/helix-view/src/commands.rs +++ b/helix-view/src/commands.rs @@ -235,6 +235,18 @@ pub fn split_selection_on_newline(view: &mut View, _count: usize) { view.state.selection = selection::split_on_matches(text, view.state.selection(), ®EX) } +pub fn select_line(view: &mut View, _count: usize) { + // TODO: count + let pos = view.state.selection().primary(); + let text = view.state.doc(); + let line = text.char_to_line(pos.head); + let start = text.line_to_char(line); + let end = text.line_to_char(line + 1); + + // TODO: use a transaction + view.state.selection = Selection::single(start, end); +} + pub fn delete_selection(view: &mut View, _count: usize) { let transaction = Transaction::change_by_selection(&view.state, |range| (range.from(), range.to(), None)); diff --git a/helix-view/src/keymap.rs b/helix-view/src/keymap.rs index da5934eb..8c53b403 100644 --- a/helix-view/src/keymap.rs +++ b/helix-view/src/keymap.rs @@ -145,6 +145,7 @@ pub fn default() -> Keymaps { vec![key!('c')] => commands::change_selection, vec![key!('s')] => commands::split_selection_on_newline, vec![key!(';')] => commands::collapse_selection, + vec![key!('x')] => commands::select_line, vec![key!('u')] => commands::undo, vec![shift!('U')] => commands::redo, vec![key!('y')] => commands::yank,