on master help sign in
commands: Implement X as extend line.
2088c45Blaž Hrastnik
helix-term/src/commands.rs+19
@@ -429,6 +429,25 @@ pub fn select_line(cx: &mut Context) {
429
429
430 doc.set_selection(Selection::single(start, end));
430 doc.set_selection(Selection::single(start, end));
431}
431}
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+}
432
451
433// heuristic: append changes to history after each command, unless we're in insert mode
452// heuristic: append changes to history after each command, unless we're in insert mode
434
453
helix-term/src/keymap.rs+1−1
@@ -177,7 +177,7 @@ pub fn default() -> Keymaps {
177 alt!(';') => commands::flip_selections,
177 alt!(';') => commands::flip_selections,
178 key!('%') => commands::select_all,
178 key!('%') => commands::select_all,
179 key!('x') => commands::select_line,
179 key!('x') => commands::select_line,
180− // key!('X') => commands::extend_line,
180+ shift!('X') => commands::extend_line,
181 // or select mode X?
181 // or select mode X?
182 // extend_to_whole_line, crop_to_whole_line
182 // extend_to_whole_line, crop_to_whole_line
183
183