Skip to content

Conversation

@Chigusa0w0
Copy link
Contributor

@Chigusa0w0 Chigusa0w0 commented Aug 20, 2021

This PR fixes microsoft/monaco-editor#2623 and similar misbehavior in VSCode up to 1.60.0-insider (i.e., editor will not respond to low-speed two-finger scrolling).

When scrolling with trackpad two-figure scrolling, or in the ending phase of an inertial scrolling, small floating pointing numbers of deltaX/deltaY will be fed to the handler. When the number is small enough, the scrollTop/scrollLeft will change by a value less than 1.

if (deltaY) {
const desiredScrollTop = futureScrollPosition.scrollTop - SCROLL_WHEEL_SENSITIVITY * deltaY;
this._verticalScrollbar.writeScrollPosition(desiredScrollPosition, desiredScrollTop);
}
if (deltaX) {
const desiredScrollLeft = futureScrollPosition.scrollLeft - SCROLL_WHEEL_SENSITIVITY * deltaX;
this._horizontalScrollbar.writeScrollPosition(desiredScrollPosition, desiredScrollLeft);
}
// Check that we are scrolling towards a location which is valid
desiredScrollPosition = this._scrollable.validateScrollPosition(desiredScrollPosition);

Unfortunately, the validateScrollPosition method, which internally calls new ScrollState(), will simply round-down the input value.

width = width | 0;
scrollWidth = scrollWidth | 0;
scrollLeft = scrollLeft | 0;
height = height | 0;
scrollHeight = scrollHeight | 0;
scrollTop = scrollTop | 0;

Therefore, for upward scrolling, users can get a smooth scrolling experience. However, for downward scrolling, VSCode/Monaco will not respond to such scrolling requests when its speed is below a certain level. With the default settings, the speed threshold is relatively high. In some cases, the difficulty of scrolling down in VSCode/Monaco is quite noticeable. For Monaco, this also means that under certain configurations such low-speed scroll events are passed to other HTML elements, causing unexpected scrolling of other elements.

This PR ensures that low-speed scrolling events from user/inertial scrolling are correctly responded to by introducing active symmetric rounding (round away from zero). The behavior is consistent with the original VSCode/Monaco upward scrolling behavior. No disruptive changes to the user experience are expected.

@alexdima
Copy link
Member

Thank you!

@alexdima alexdima merged commit 9ad55d5 into microsoft:main Aug 23, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Oct 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Monaco cannot properly consume low-speed two finger scroll events

2 participants