on master help sign in
Implement `X` as extend selection to line bounds
a4e28c6Blaž Hrastnik
book/src/keymap.md+1
@@ -73,6 +73,7 @@
73| `Alt-;` | Flip selection cursor and anchor |
73| `Alt-;` | Flip selection cursor and anchor |
74| `%` | Select entire file |
74| `%` | Select entire file |
75| `x` | Select current line, if already selected, extend to next line |
75| `x` | Select current line, if already selected, extend to next line |
76+| `X` | Extend selection to line bounds (line-wise selection) |
76| | Expand selection to parent syntax node TODO: pick a key |
77| | Expand selection to parent syntax node TODO: pick a key |
77| `J` | join lines inside selection |
78| `J` | join lines inside selection |
78| `K` | keep selections matching the regex TODO: overlapped by hover help |
79| `K` | keep selections matching the regex TODO: overlapped by hover help |
helix-term/src/commands.rs+21
@@ -200,6 +200,7 @@ impl Command {
200 extend_search_next,
200 extend_search_next,
201 search_selection,
201 search_selection,
202 extend_line,
202 extend_line,
203+ extend_to_line_bounds,
203 delete_selection,
204 delete_selection,
204 change_selection,
205 change_selection,
205 collapse_selection,
206 collapse_selection,
@@ -1021,6 +1022,26 @@ fn extend_line(cx: &mut Context) {
1021 doc.set_selection(view.id, Selection::single(start, end));
1022 doc.set_selection(view.id, Selection::single(start, end));
1022}
1023}
1023
1024
1025+fn extend_to_line_bounds(cx: &mut Context) {
1026+ let (view, doc) = current!(cx.editor);
1027+
1028+ let text = doc.text();
1029+ let selection = doc.selection(view.id).transform(|range| {
1030+ let start = text.line_to_char(text.char_to_line(range.from()));
1031+ let end = text
1032+ .line_to_char(text.char_to_line(range.to()) + 1)
1033+ .saturating_sub(1);
1034+
1035+ if range.anchor < range.head {
1036+ Range::new(start, end)
1037+ } else {
1038+ Range::new(end, start)
1039+ }
1040+ });
1041+
1042+ doc.set_selection(view.id, selection);
1043+}
1044+
1024fn delete_selection_impl(reg: &mut Register, doc: &mut Document, view_id: ViewId) {
1045fn delete_selection_impl(reg: &mut Register, doc: &mut Document, view_id: ViewId) {
1025 // first yank the selection
1046 // first yank the selection
1026 let values: Vec<String> = doc
1047 let values: Vec<String> = doc
helix-term/src/keymap.rs+3−1
@@ -209,7 +209,9 @@ impl Default for Keymaps {
209 alt!(';') => Command::flip_selections,
209 alt!(';') => Command::flip_selections,
210 key!('%') => Command::select_all,
210 key!('%') => Command::select_all,
211 key!('x') => Command::extend_line,
211 key!('x') => Command::extend_line,
212+ key!('x') => Command::extend_line,
213+ key!('X') => Command::extend_to_line_bounds,
212− // extend_to_whole_line, crop_to_whole_line
214+ // crop_to_whole_line
213
215
214
216
215 key!('m') => Command::match_mode,
217 key!('m') => Command::match_mode,