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 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
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.saturating_sub(scrolloff));
.min(last_line.saturating_sub(scrolloff))
.max(view.offset.row + scrolloff);

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

Expand Down