Clear the mousewheelScreenRow even if the event does not cause scrolling

If a mousewheel event is triggered when the editor can't be scrolled,
we still want to clear the mouseWheelScreenRow. This is typically done
when we stop scrolling, but if we never start scrolling it will never
happen. This commit adds another timeout to cover that case.
This commit is contained in:
Nathan Sobo
2014-05-31 18:36:59 +09:00
parent 115a7e1dfb
commit 2548891b99
2 changed files with 26 additions and 0 deletions

View File

@@ -790,6 +790,22 @@ describe "EditorComponent", ->
expect(component.mouseWheelScreenRow).toBe null
it "clears the mouseWheelScreenRow after a delay even if the event does not cause scrolling", ->
spyOn(_._, 'now').andCallFake -> window.now # Ensure _.debounce is based on our fake spec timeline
expect(editor.getScrollTop()).toBe 0
lineNode = node.querySelector('.line')
wheelEvent = new WheelEvent('mousewheel', wheelDeltaX: 0, wheelDeltaY: 10)
Object.defineProperty(wheelEvent, 'target', get: -> lineNode)
node.dispatchEvent(wheelEvent)
expect(editor.getScrollTop()).toBe 0
expect(component.mouseWheelScreenRow).toBe 0
advanceClock(component.mouseWheelScreenRowClearDelay)
expect(component.mouseWheelScreenRow).toBe null
it "does not preserve the line if it is on screen", ->
expect(node.querySelectorAll('.line-number').length).toBe 14 # dummy line
lineNodes = node.querySelectorAll('.line')

View File

@@ -29,6 +29,7 @@ EditorComponent = React.createClass
pendingVerticalScrollDelta: 0
pendingHorizontalScrollDelta: 0
mouseWheelScreenRow: null
mouseWheelScreenRowClearDelay: 150
render: ->
{focused, fontSize, lineHeight, fontFamily, showIndentGuide, showInvisibles, visible} = @state
@@ -370,6 +371,8 @@ EditorComponent = React.createClass
# Scrolling vertically
@pendingVerticalScrollDelta -= wheelDeltaY
@mouseWheelScreenRow = @screenRowForNode(event.target)
@clearMouseWheelScreenRowAfterDelay ?= debounce(@clearMouseWheelScreenRow, @mouseWheelScreenRowClearDelay)
@clearMouseWheelScreenRowAfterDelay()
unless animationFramePending
requestAnimationFrame =>
@@ -379,6 +382,13 @@ EditorComponent = React.createClass
@pendingVerticalScrollDelta = 0
@pendingHorizontalScrollDelta = 0
clearMouseWheelScreenRow: ->
if @mouseWheelScreenRow?
@mouseWheelScreenRow = null
@requestUpdate()
clearMouseWheelScreenRowAfterDelay: null # created lazily
screenRowForNode: (node) ->
while node isnt document
if screenRow = node.dataset.screenRow