on master help sign in
Implement `X` as extend selection to line bounds
commita4e28c6927e59cf08d056e9c9a74be095eae5f29 authorBlaž Hrastnik <blaz@mxxn.io> dateMon 5 Jul 2021, 10:12 (5 years ago) parentd02bbb7
3 files changed+25−1
book/src/keymap.md+1 helix-term/src/commands.rs+21 helix-term/src/keymap.rs+3−1
book/src/keymap.md+1
@@ -73,6 +73,7 @@
7373| `Alt-;` | Flip selection cursor and anchor |
7474| `%` | Select entire file |
7575| `x` | Select current line, if already selected, extend to next line |
76+| `X` | Extend selection to line bounds (line-wise selection) |
7677| | Expand selection to parent syntax node TODO: pick a key |
7778| `J` | join lines inside selection |
7879| `K` | keep selections matching the regex TODO: overlapped by hover help |
helix-term/src/commands.rs+21
@@ -200,6 +200,7 @@ impl Command {
200200 extend_search_next,
201201 search_selection,
202202 extend_line,
203+ extend_to_line_bounds,
203204 delete_selection,
204205 change_selection,
205206 collapse_selection,
@@ -1021,6 +1022,26 @@ fn extend_line(cx: &mut Context) {
10211022 doc.set_selection(view.id, Selection::single(start, end));
10221023}
10231024
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+
10241045fn delete_selection_impl(reg: &mut Register, doc: &mut Document, view_id: ViewId) {
10251046 // first yank the selection
10261047 let values: Vec<String> = doc
helix-term/src/keymap.rs+3−1
@@ -209,7 +209,9 @@ impl Default for Keymaps {
209209 alt!(';') => Command::flip_selections,
210210 key!('%') => Command::select_all,
211211 key!('x') => Command::extend_line,
212− // extend_to_whole_line, crop_to_whole_line
212+ key!('x') => Command::extend_line,
213+ key!('X') => Command::extend_to_line_bounds,
214+ // crop_to_whole_line
213215
214216
215217 key!('m') => Command::match_mode,