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

helix-view: Fix jumpy cursor on vertical center #10795

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Aleksbgbg
Copy link

Previously, in the case where a high scrolloff was configured in order to center the cursor vertically, the scrolloff would be clamped to a maximum value - the number of lines above and below the center line.

The problem with this approach is that in the case where there are an even number of lines in the view, there are two center lines, and so the cursor would be allowed to visit them both without shifting the view.

To remedy the issue, dedicate the topmost center line as the true center, by splitting the scrolloff value into a top and bottom component where the bottom is one higher than the top.

In all other cases, the behaviour remains the same by setting both components to the same value as the original scrolloff.

@Aleksbgbg
Copy link
Author

I just noticed the use of scrolloff in horizontal offset underneath (https://github.com/helix-editor/helix/pull/10795/files#diff-18195c1eaadd7a2747b6556008c6022d79f814d64624e9e69d0735a3e0bbe296R292-R298) that I didn't update. This causes a bug with horizontal scrolling.

@pascalkuthe could you explain why scrolloff is used on those lines? How does scrolloff (which I always assumed was vertical) relate to horizontal offset?

@Aleksbgbg Aleksbgbg marked this pull request as draft May 20, 2024 19:50
Previously, in the case where a high scrolloff was configured in order
to center the cursor vertically, the scrolloff would be clamped to a
maximum value - the number of lines above and below the center line.

The problem with this approach is that in the case where there are an
even number of lines in the view, there are two center lines, and so the
cursor would be allowed to visit them both without shifting the view.

To remedy the issue, dedicate the topmost center line as the true
center, by splitting the scrolloff value into a top and bottom component
where the bottom is one higher than the top.

In all other cases, the behaviour remains the same by setting both
components to the same value as the original scrolloff.
@Aleksbgbg Aleksbgbg marked this pull request as ready for review May 22, 2024 20:59
@Aleksbgbg
Copy link
Author

I fixed the issue above by using the original scrolloff (scrolloff_top) for the horiontal calculations. This works fine and could be merged now, but perhaps I could clean it up with a better understanding of the usage there.

} else if (viewport.height % 2) == 1 {
(max_scrolloff, max_scrolloff)
} else {
(max_scrolloff.saturating_sub(1), max_scrolloff)
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably useful to keep the comment there for the last two blocks of the if

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants