-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Changes from 7 commits
02408a3
26ce99a
9686b5e
93e8774
a58eb04
8960c70
e19575c
cc393df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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)), | ||
} | ||
.min(last_line.saturating_sub(scrolloff)); | ||
.min((view.offset.row + height - 1).saturating_sub(scrolloff)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saturating_sub
should already protect against overflow here.