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

Fixes #2754. Ctrl+d/u pull cursor along when screen moves past cursor #3658

Merged
merged 2 commits into from Apr 30, 2019
Merged

Fixes #2754. Ctrl+d/u pull cursor along when screen moves past cursor #3658

merged 2 commits into from Apr 30, 2019

Conversation

novaluke
Copy link
Contributor

@novaluke novaluke commented Apr 5, 2019

What this PR does / why we need it:

Current implementation of ctrl+d/ctrl+u does not allow scrolling past the cursor's original position when smooth scrolling is enabled (see #2754). With this PR, when ctrl+d/ctrl+u scroll the screen such that the cursor would be off-screen, the cursor is placed at the first/last line respectively rather than the screen snapping back to keep the cursor in view.

Which issue(s) this PR fixes

#2754

Special notes for your reviewer:

As I understand it, when VSCodeVim executes ctrl+d or ctrl+u, it checks the range of lines on the screen and then places the cursor at an offset (relative to the new first line) equal to the offset prior to scrolling. This is the ideal behavior normally, but when smooth scrolling is enabled the new range of lines is not available to the VSCodeVim command (due to scrolling happening asynchronously). It ends up accessing the original range of lines instead, which means the new position is calculated relative to (and identical to) the original position. This causes the cursor to not be moved and prevents the screen from scrolling any further than the cursor.

This change "fixes" the issue by using a built-in feature of VSCode's scrolling command. By setting revealCursor to true in the scroll command VSCode will ensure the cursor gets "pulled along" when scrolling it off-screen, and telling VSCodeVim to use that new position ensures VSCodeVim doesn't reset it back.

Caveat: This doesn't keep the proper vertical offset when scrolling, so isn't quite a "true" fix, especially as the functionality differs slightly between having smooth scrolling on and off (it as at least usable now, though).

@novaluke
Copy link
Contributor Author

@jpoon Pretty sure this PR is ready for merge, assuming the tradeoffs are acceptable. Got time for a 👍/👎? 😄

src/actions/commands/actions.ts Outdated Show resolved Hide resolved
src/actions/commands/actions.ts Outdated Show resolved Hide resolved
let newPosition;
let newPosition: Position;
if (!smoothScrolling) {
const newFirstLine = editor.visibleRanges[0].start.line;
Copy link
Member

Choose a reason for hiding this comment

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

same as firstLine var?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as newFirstLine from before this commit (line 681 above). firstLine is the first line before the scroll, newFirstLine is the first line after the scroll.

src/actions/commands/actions.ts Outdated Show resolved Hide resolved
src/actions/commands/actions.ts Outdated Show resolved Hide resolved
@novaluke
Copy link
Contributor Author

Thanks for the review @jpoon - I believe everything should be fixed/addressed now.

@jpoon jpoon merged commit 4181204 into VSCodeVim:master Apr 30, 2019
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