aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-03-01 05:41:02 +0000
committerBlaž Hrastnik2021-03-01 05:41:02 +0000
commit2088c45075875cd069a2c403ee76028146487bb0 (patch)
tree67a054225b5d7f19e23b034ec37d9b628936a459 /helix-term
parent4102992c4624f8d66c0285bb9d4925153a464c9b (diff)
commands: Implement X as extend line.
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs19
-rw-r--r--helix-term/src/keymap.rs2
2 files changed, 20 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 28caa6d5..55cbf0fe 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -429,6 +429,25 @@ pub fn select_line(cx: &mut Context) {
doc.set_selection(Selection::single(start, end));
}
+pub fn extend_line(cx: &mut Context) {
+ let count = cx.count;
+ let doc = cx.doc();
+
+ let pos = doc.selection().primary();
+ let text = doc.text();
+
+ let line_start = text.char_to_line(pos.anchor);
+ let mut line = text.char_to_line(pos.head);
+ let line_end = text.line_to_char(line + 1).saturating_sub(1);
+ if line_start <= pos.anchor && pos.head == line_end && line != text.len_lines() {
+ line += 1;
+ }
+
+ let start = text.line_to_char(line_start);
+ let end = text.line_to_char(line + 1).saturating_sub(1);
+
+ doc.set_selection(Selection::single(start, end));
+}
// heuristic: append changes to history after each command, unless we're in insert mode
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index 24c5eee8..395ddd9a 100644
--- a/helix-term/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -177,7 +177,7 @@ pub fn default() -> Keymaps {
alt!(';') => commands::flip_selections,
key!('%') => commands::select_all,
key!('x') => commands::select_line,
- // key!('X') => commands::extend_line,
+ shift!('X') => commands::extend_line,
// or select mode X?
// extend_to_whole_line, crop_to_whole_line