Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform extend line on every selection #1804

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Perform extend line on every selection
Currently `x` only affect the current selection, but this will make it
affect every selection so `x` can be more useful with multi-cursors.
  • Loading branch information
pickfire committed Mar 13, 2022
commit 8730388cdaaf2d42886593c310f1e65ed35b42a5
19 changes: 11 additions & 8 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down