Skip to content

Conversation

@towerofnix
Copy link
Contributor

Fixes #156.

This is a "workaround" for browsers which do not automatically set deltaX when the shift key is held (seen on Firefox-Linux and Chrome-Windows, but not Chrome-Mac). This PR makes it so that when the shift key is held while scrolling, deltaX is ignored, and the distance scrolled horizontally is set to deltaY.

This might have a strange effect on macbooks with trackpads (suddenly the distance you move your fingers left/right has no effect and horizontal scrolling is based on up/down finger movement), but I think that's acceptable - it would be obvious that it only behaves that way when shift is held, and wouldn't be too difficult to intuit anyways.

Tested locally on Firefox/Linux.

Copy link
Contributor

@fsih fsih left a comment

Choose a reason for hiding this comment

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

I tried this out in Chrome on Windows, and it works well with mouse scroll!

On Windows and Mac, the touchpad behavior is as you described, where it only scrolls horizontally if you hold shift. I agree that that case seems less important.

On Mac though, this breaks horizontal mouse scroll, since holding shift causes scrolling to do nothing /:

@towerofnix
Copy link
Contributor Author

towerofnix commented Jan 23, 2018

Thanks for testing, @fsih!

I made a change which only runs this workaround if event.deltaX is zero (and shift is pressed, of course). In that case, we know that the user probably wants to scroll horizontally, but deltaX isn't being set, so the "scroll horizontally by deltaX" block certainly won't work, and we have a go at using deltaY as the horizontal scroll distance.

@towerofnix
Copy link
Contributor Author

This does make trackpad-scrolling while shift is held just a little more funky, though, since now the workaround only applies if the user is scrolling strictly vertically. So when you're scrolling to the side at all, it goes back to using the normal scroll method, and the horizontal movement works as you'd normally expect. But if you're scrolling strictly vertically while shift is pressed, the editor pans horizontally!

Copy link
Contributor

@fsih fsih left a comment

Choose a reason for hiding this comment

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

Cool, looks good!

I tried it out on a Mac touchpad, and the scroll kind of jitters sometimes but works almost normally. Maybe if you're resizing something with shift held, and it's going off the edge, you might want to scroll while holding shift, but that's pretty out there.

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.

2 participants