Simplify edge calculation when scrolling down #1194
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When scrolling with a very large
scrolloff
value, the cursor will be positioned in the middle of the column, and theedge
variable represents how far the cursor is from the top/bottom row. If the height is an odd number, then this is straightforward, but if the height is an even number, then there are two candidate rows for the middle (lf
uses the bottom one).For example:
edge
is simply 4 on both sidesedge
is 5 when scrolling up, but 4 when scrolling downAs part of the calculations, the current code effectively tries to determine
min(nav.height/2, nav.height/2+nav.height%2-1)
which can be simplified (h
to represent the height for the following):h % 2 - 1
is always equal to0
or-1
, which meansh / 2
can never be smaller thanh / 2 + h % 2 - 1
, and therefore the calculation can be collapsed to the latter.h / 2 + h % 2 - 1
means to halve and subtract 1 if the height is an even number, and integer divide by 2 if it is an odd number, so the calculation can further be simplified to(h - 1) / 2
.