aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorIvan Tham2022-03-14 02:45:45 +0000
committerGitHub2022-03-14 02:45:45 +0000
commit29d6a5a9b6fde7b9e82b6abceef892fba42d8da4 (patch)
tree4a5a280b082c648194daae8d90ecbf0a0ed397b3 /helix-term
parent3d76fa0b81c3f5cef7a8acdfa92b26004e610752 (diff)
Perform extend line on every selection (#1804)
Currently `x` only affect the current selection, but this will make it affect every selection so `x` can be more useful with multi-cursors.
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index fc5dc16d..ff3fb925 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1841,17 +1841,20 @@ fn extend_line(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
let text = doc.text();
- let range = doc.selection(view.id).primary();
+ let selection = doc.selection(view.id).clone().transform(|range| {
+ let (start_line, end_line) = range.line_range(text.slice(..));
- let (start_line, end_line) = range.line_range(text.slice(..));
- let start = text.line_to_char(start_line);
- let mut end = text.line_to_char((end_line + count).min(text.len_lines()));
+ let start = text.line_to_char(start_line);
+ let mut end = text.line_to_char((end_line + count).min(text.len_lines()));
- if range.from() == start && range.to() == end {
- end = text.line_to_char((end_line + count + 1).min(text.len_lines()));
- }
+ // go to next line if current line is selected
+ if range.from() == start && range.to() == end {
+ end = text.line_to_char((end_line + count + 1).min(text.len_lines()));
+ }
+ Range::new(start, end)
+ });
- doc.set_selection(view.id, Selection::single(start, end));
+ doc.set_selection(view.id, selection);
}
fn extend_to_line_bounds(cx: &mut Context) {