on master help sign in
commands: Implement X as extend line.
commit2088c45075875cd069a2c403ee76028146487bb0 authorBlaž Hrastnik <blaz@mxxn.io> dateMon 1 Mar 2021, 14:41 (6 years ago) parent4102992
2 files changed+20−1
helix-term/src/commands.rs+19 helix-term/src/keymap.rs+1−1
helix-term/src/commands.rs+19
@@ -429,6 +429,25 @@ pub fn select_line(cx: &mut Context) {
429429
430430 doc.set_selection(Selection::single(start, end));
431431}
432+pub fn extend_line(cx: &mut Context) {
433+ let count = cx.count;
434+ let doc = cx.doc();
435+
436+ let pos = doc.selection().primary();
437+ let text = doc.text();
438+
439+ let line_start = text.char_to_line(pos.anchor);
440+ let mut line = text.char_to_line(pos.head);
441+ let line_end = text.line_to_char(line + 1).saturating_sub(1);
442+ if line_start <= pos.anchor && pos.head == line_end && line != text.len_lines() {
443+ line += 1;
444+ }
445+
446+ let start = text.line_to_char(line_start);
447+ let end = text.line_to_char(line + 1).saturating_sub(1);
448+
449+ doc.set_selection(Selection::single(start, end));
450+}
432451
433452// heuristic: append changes to history after each command, unless we're in insert mode
434453
helix-term/src/keymap.rs+1−1
@@ -177,7 +177,7 @@ pub fn default() -> Keymaps {
177177 alt!(';') => commands::flip_selections,
178178 key!('%') => commands::select_all,
179179 key!('x') => commands::select_line,
180− // key!('X') => commands::extend_line,
180+ shift!('X') => commands::extend_line,
181181 // or select mode X?
182182 // extend_to_whole_line, crop_to_whole_line
183183