Stop scaling up small scroll wheel events

This commit is contained in:
Billy Janitsch
2018-02-15 10:42:57 -08:00
parent 3078c4d14f
commit a433e974eb
2 changed files with 2 additions and 40 deletions

View File

@@ -1368,40 +1368,6 @@ describe('TextEditorComponent', () => {
}
})
it('always scrolls by a minimum of 1, even when the delta is small or the scroll sensitivity is low', () => {
const scrollSensitivity = 10
const {component, editor} = buildComponent({height: 50, width: 50, scrollSensitivity})
{
component.didMouseWheel({wheelDeltaX: 0, wheelDeltaY: -3})
expect(component.getScrollTop()).toBe(1)
expect(component.getScrollLeft()).toBe(0)
expect(component.refs.content.style.transform).toBe(`translate(0px, -1px)`)
}
{
component.didMouseWheel({wheelDeltaX: -4, wheelDeltaY: 0})
expect(component.getScrollTop()).toBe(1)
expect(component.getScrollLeft()).toBe(1)
expect(component.refs.content.style.transform).toBe(`translate(-1px, -1px)`)
}
editor.update({scrollSensitivity: 100})
{
component.didMouseWheel({wheelDeltaX: 0, wheelDeltaY: 0.3})
expect(component.getScrollTop()).toBe(0)
expect(component.getScrollLeft()).toBe(1)
expect(component.refs.content.style.transform).toBe(`translate(-1px, 0px)`)
}
{
component.didMouseWheel({wheelDeltaX: 0.1, wheelDeltaY: 0})
expect(component.getScrollTop()).toBe(0)
expect(component.getScrollLeft()).toBe(0)
expect(component.refs.content.style.transform).toBe(`translate(0px, 0px)`)
}
})
it('inverts deltaX and deltaY when holding shift on Windows and Linux', async () => {
const scrollSensitivity = 50
const {component, editor} = buildComponent({height: 50, width: 50, scrollSensitivity})

View File

@@ -1520,15 +1520,11 @@ class TextEditorComponent {
let {wheelDeltaX, wheelDeltaY} = event
if (Math.abs(wheelDeltaX) > Math.abs(wheelDeltaY)) {
wheelDeltaX = (Math.sign(wheelDeltaX) === 1)
? Math.max(1, wheelDeltaX * scrollSensitivity)
: Math.min(-1, wheelDeltaX * scrollSensitivity)
wheelDeltaX = wheelDeltaX * scrollSensitivity
wheelDeltaY = 0
} else {
wheelDeltaX = 0
wheelDeltaY = (Math.sign(wheelDeltaY) === 1)
? Math.max(1, wheelDeltaY * scrollSensitivity)
: Math.min(-1, wheelDeltaY * scrollSensitivity)
wheelDeltaY = wheelDeltaY * scrollSensitivity
}
if (this.getPlatform() !== 'darwin' && event.shiftKey) {