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

Add command to extend selection to line above #2117

Merged
merged 3 commits into from
Apr 17, 2022

Conversation

AntonioLucibello
Copy link
Contributor

@AntonioLucibello AntonioLucibello commented Apr 15, 2022

Equivalent to extend_line, but extends selection above rather than below.

One limitation I don't quite know how to fix is that currently it doesn't scroll the view upwards once it reaches the top of the screen. I figure it's because the "main cursor" stays at the bottom of the selection, so the view does not scroll to contain the top of the selection the same way it does for the bottom.

@EpocSquadron
Copy link
Contributor

Could we ensure the direction of the cursor is reverse to solve that?

Comment on lines 1879 to 1898
fn extend_line_above(cx: &mut Context) {
let count = cx.count();
let (view, doc) = current!(cx.editor);

let text = doc.text();
let selection = doc.selection(view.id).clone().transform(|range| {
let (start_line, end_line) = range.line_range(text.slice(..));

let mut start = text.line_to_char(start_line);
let end = text.line_to_char((end_line + count).min(text.len_lines()));

// go to previous line if current line is selected
if range.from() == start && range.to() == end {
start = text.line_to_char(start_line.saturating_sub(1));
}
Range::new(end, start)
});

doc.set_selection(view.id, selection);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lot of duplication for essentially changing two lines. Can you factor out the common implementation in a similar way we do for other commands like https://github.com/helix-editor/helix/blob/b6e452151196bf773874d266f9bf82e7386e56ef/helix-term/src/commands.rs#L4349-L4380=

@archseer archseer merged commit b67e061 into helix-editor:master Apr 17, 2022
@sudormrfbin
Copy link
Member

This should be added to the docs (with a default keybind too maybe ?).

@AntonioLucibello
Copy link
Contributor Author

AntonioLucibello commented Apr 17, 2022

Keybinds are being discussed in #2130 (alongside a refactor of how x works in general).
We seem to be leaning towards X for extend_line_above, but that leaves the problem of what to move extend_to_line_bounds to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants