mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Only prevent default on mousewheel events if editor actually scrolls
This prevents mini editors from capturing scroll events.
This commit is contained in:
@@ -1687,6 +1687,42 @@ describe "EditorComponent", ->
|
||||
|
||||
expect(componentNode.contains(lineNumberNode)).toBe true
|
||||
|
||||
it "only prevents the default action of the mousewheel event if it actually lead to scrolling", ->
|
||||
spyOn(WheelEvent::, 'preventDefault').andCallThrough()
|
||||
|
||||
wrapperNode.style.height = 4.5 * lineHeightInPixels + 'px'
|
||||
wrapperNode.style.width = 20 * charWidth + 'px'
|
||||
component.measureHeightAndWidth()
|
||||
runSetImmediateCallbacks()
|
||||
|
||||
componentNode.dispatchEvent(new WheelEvent('mousewheel', wheelDeltaX: 0, wheelDeltaY: 50))
|
||||
expect(editor.getScrollTop()).toBe 0
|
||||
expect(WheelEvent::preventDefault).not.toHaveBeenCalled()
|
||||
|
||||
componentNode.dispatchEvent(new WheelEvent('mousewheel', wheelDeltaX: 0, wheelDeltaY: -3000))
|
||||
runSetImmediateCallbacks()
|
||||
expect(editor.getScrollTop()).toBe editor.getScrollHeight() - editor.getHeight() + 15
|
||||
expect(WheelEvent::preventDefault).toHaveBeenCalled()
|
||||
WheelEvent::preventDefault.reset()
|
||||
|
||||
componentNode.dispatchEvent(new WheelEvent('mousewheel', wheelDeltaX: 0, wheelDeltaY: -30))
|
||||
expect(editor.getScrollTop()).toBe editor.getScrollHeight() - editor.getHeight() + 15
|
||||
expect(WheelEvent::preventDefault).not.toHaveBeenCalled()
|
||||
|
||||
componentNode.dispatchEvent(new WheelEvent('mousewheel', wheelDeltaX: 50, wheelDeltaY: 0))
|
||||
expect(editor.getScrollLeft()).toBe 0
|
||||
expect(WheelEvent::preventDefault).not.toHaveBeenCalled()
|
||||
|
||||
componentNode.dispatchEvent(new WheelEvent('mousewheel', wheelDeltaX: -3000, wheelDeltaY: 0))
|
||||
runSetImmediateCallbacks()
|
||||
expect(editor.getScrollLeft()).toBe editor.getScrollWidth() - editor.getWidth() + 15
|
||||
expect(WheelEvent::preventDefault).toHaveBeenCalled()
|
||||
WheelEvent::preventDefault.reset()
|
||||
|
||||
componentNode.dispatchEvent(new WheelEvent('mousewheel', wheelDeltaX: -30, wheelDeltaY: 0))
|
||||
expect(editor.getScrollLeft()).toBe editor.getScrollWidth() - editor.getWidth() + 15
|
||||
expect(WheelEvent::preventDefault).not.toHaveBeenCalled()
|
||||
|
||||
describe "input events", ->
|
||||
inputNode = null
|
||||
|
||||
|
||||
@@ -567,20 +567,23 @@ EditorComponent = React.createClass
|
||||
@pendingScrollLeft = null
|
||||
|
||||
onMouseWheel: (event) ->
|
||||
event.preventDefault()
|
||||
{editor} = @props
|
||||
|
||||
# Only scroll in one direction at a time
|
||||
{wheelDeltaX, wheelDeltaY} = event
|
||||
if Math.abs(wheelDeltaX) > Math.abs(wheelDeltaY)
|
||||
# Scrolling horizontally
|
||||
editor.setScrollLeft(editor.getScrollLeft() - Math.round(wheelDeltaX * @scrollSensitivity))
|
||||
previousScrollLeft = editor.getScrollLeft()
|
||||
editor.setScrollLeft(previousScrollLeft - Math.round(wheelDeltaX * @scrollSensitivity))
|
||||
event.preventDefault() unless previousScrollLeft is editor.getScrollLeft()
|
||||
else
|
||||
# Scrolling vertically
|
||||
@mouseWheelScreenRow = @screenRowForNode(event.target)
|
||||
@clearMouseWheelScreenRowAfterDelay ?= debounce(@clearMouseWheelScreenRow, @mouseWheelScreenRowClearDelay)
|
||||
@clearMouseWheelScreenRowAfterDelay()
|
||||
editor.setScrollTop(editor.getScrollTop() - Math.round(wheelDeltaY * @scrollSensitivity))
|
||||
previousScrollTop = editor.getScrollTop()
|
||||
editor.setScrollTop(previousScrollTop - Math.round(wheelDeltaY * @scrollSensitivity))
|
||||
event.preventDefault() unless previousScrollTop is editor.getScrollTop()
|
||||
|
||||
onScrollViewScroll: ->
|
||||
if @isMounted()
|
||||
|
||||
Reference in New Issue
Block a user