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 7 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
11 changes: 7 additions & 4 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,12 @@ fn trim_selections(cx: &mut Context) {
}

fn goto_window(cx: &mut Context, align: Align) {
let count = cx.count() - 1;
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
Expand All @@ -638,11 +640,12 @@ fn goto_window(cx: &mut Context, align: Align) {
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),
Align::Top => (view.offset.row + scrolloff + count),
Align::Center => (view.offset.row + ((last_line - view.offset.row) / 2)),
Align::Bottom => last_line.saturating_sub((scrolloff + count).min(last_line)),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Align::Bottom => last_line.saturating_sub((scrolloff + count).min(last_line)),
Align::Bottom => last_line.saturating_sub((scrolloff + count)),

saturating_sub should already protect against overflow here.

}
.min(last_line.saturating_sub(scrolloff));
.min((view.offset.row + height - 1).saturating_sub(scrolloff))
Copy link
Member

Choose a reason for hiding this comment

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

What was wrong with the previous bound? I don't think this is correct, since view.offset + height - 1 can be past last_line of the document

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I already used last_line in the before computation , I think we need ensure we won't go beyond the scroll off line of the bottom. For example if the content is only half page, we subtract last_line with scroll off is pointless because it's far from scrolling.

.max(view.offset.row + scrolloff);

let pos = doc.text().line_to_char(line);

Expand Down