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

accept count for goto_window #1033

Merged
merged 8 commits into from
Nov 29, 2021
Merged
Changes from 3 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
14 changes: 11 additions & 3 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,21 +581,29 @@ fn goto_first_nonwhitespace(cx: &mut Context) {
}

fn goto_window(cx: &mut Context, align: Align) {
let count = cx.count.map(|_| cx.count() - 1);
QiBaobin marked this conversation as resolved.
Show resolved Hide resolved
let (view, doc) = current!(cx.editor);

let height = view.inner_area().height as usize;

// respect user given count if any
// - 1 so we have at least one gap in the middle.
// a height of 6 with padding of 3 on each side will keep shifting the view back and forth
// as we type
let scrolloff = cx.editor.config.scrolloff.min(height.saturating_sub(1) / 2);
let scrolloff =
count.unwrap_or_else(|| cx.editor.config.scrolloff.min(height.saturating_sub(1) / 2));
Copy link
Contributor

@pickfire pickfire Nov 14, 2021

Choose a reason for hiding this comment

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

I think it would better to follow the vim behavior here of having count starting from scrolloff point, otherwise 1gt would result in moving the screen by scrolloff.

But vim behavior here is good I think. If the screen is at the corner of the screen (0 or file end), 1H will go to the first line without scrolloff (same for the end), and if the screen is being scrolled to the middle, 1H will go to the first scrolloff position rather than the top. This is the nicer behavior but I think it is a bit more complicated to implement.

And with large scrolloff count it doesn't move the screen, so <n>H in vim won't change the screen in any bits, it will move to the last scrolloff point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, please take a another look


let last_line = view.last_line(doc);

let line = match align {
Align::Top => (view.offset.row + scrolloff),
Align::Center => (view.offset.row + (height / 2)),
Align::Bottom => last_line.saturating_sub(scrolloff),
// the last line might far above height, so use content middle if the view is not fulfilled
Align::Center => (view.offset.row + ((last_line - view.offset.row) / 2)),
// the last line might far above height, so se use last line if the view is not fulfilled
Align::Bottom => std::cmp::min(
last_line,
(view.offset.row + height - 1).saturating_sub(scrolloff),
),
}
.min(last_line.saturating_sub(scrolloff));

Expand Down