on master help sign in
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.

commit29d6a5a9b6fde7b9e82b6abceef892fba42d8da4 authorIvan Tham <pickfire@riseup.net> dateMon 14 Mar 2022, 10:45 (5 years ago) parent3d76fa0
1 file changed+11−8
helix-term/src/commands.rs+11−8
helix-term/src/commands.rs+11−8
@@ -1841,17 +1841,20 @@ fn extend_line(cx: &mut Context) {
18411841 let (view, doc) = current!(cx.editor);
18421842
18431843 let text = doc.text();
1844− let range = doc.selection(view.id).primary();
1844+ let selection = doc.selection(view.id).clone().transform(|range| {
1845+ let (start_line, end_line) = range.line_range(text.slice(..));
18451846
1846− let (start_line, end_line) = range.line_range(text.slice(..));
1847− let start = text.line_to_char(start_line);
1848− let mut end = text.line_to_char((end_line + count).min(text.len_lines()));
1847+ let start = text.line_to_char(start_line);
1848+ let mut end = text.line_to_char((end_line + count).min(text.len_lines()));
18491849
1850− if range.from() == start && range.to() == end {
1851− end = text.line_to_char((end_line + count + 1).min(text.len_lines()));
1852− }
1850+ // go to next line if current line is selected
1851+ if range.from() == start && range.to() == end {
1852+ end = text.line_to_char((end_line + count + 1).min(text.len_lines()));
1853+ }
1854+ Range::new(start, end)
1855+ });
18531856
1854− doc.set_selection(view.id, Selection::single(start, end));
1857+ doc.set_selection(view.id, selection);
18551858}
18561859
18571860fn extend_to_line_bounds(cx: &mut Context) {