aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-07-05 01:12:34 +0000
committerBlaž Hrastnik2021-07-05 01:12:34 +0000
commita4e28c6927e59cf08d056e9c9a74be095eae5f29 (patch)
treeae517e0e4b6a80988d2cf1086b8b5e95355d944f /helix-term/src/commands.rs
parentd02bbb7baec13e4d3c7ae0094431f2a20526cf18 (diff)
Implement `X` as extend selection to line bounds
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index d8892c9c..63b91942 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -200,6 +200,7 @@ impl Command {
extend_search_next,
search_selection,
extend_line,
+ extend_to_line_bounds,
delete_selection,
change_selection,
collapse_selection,
@@ -1021,6 +1022,26 @@ fn extend_line(cx: &mut Context) {
doc.set_selection(view.id, Selection::single(start, end));
}
+fn extend_to_line_bounds(cx: &mut Context) {
+ let (view, doc) = current!(cx.editor);
+
+ let text = doc.text();
+ let selection = doc.selection(view.id).transform(|range| {
+ let start = text.line_to_char(text.char_to_line(range.from()));
+ let end = text
+ .line_to_char(text.char_to_line(range.to()) + 1)
+ .saturating_sub(1);
+
+ if range.anchor < range.head {
+ Range::new(start, end)
+ } else {
+ Range::new(end, start)
+ }
+ });
+
+ doc.set_selection(view.id, selection);
+}
+
fn delete_selection_impl(reg: &mut Register, doc: &mut Document, view_id: ViewId) {
// first yank the selection
let values: Vec<String> = doc