diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index 271ea856a..e01fbb853 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -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') diff --git a/src/editor-component.coffee b/src/editor-component.coffee index de2e40ddb..ede23e203 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -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