From 0043072ecffa581155ff88f8b25a7360ca60afc5 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 29 May 2014 20:54:29 -0600 Subject: [PATCH] Only preserve mouseWheelScreenRow if it's out of the rendered row range Fixes #2429, #2443 Otherwise, it's possible to duplicate lines. If a line is in the rendered row range and it's not in the set of lines returned by the editor, we should remove it no matter what. Line preservation is only intended for lines that are out of view. --- spec/editor-component-spec.coffee | 15 +++++++++++++++ src/editor-component.coffee | 7 +++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/spec/editor-component-spec.coffee b/spec/editor-component-spec.coffee index feebc299f..8733db9ce 100644 --- a/spec/editor-component-spec.coffee +++ b/spec/editor-component-spec.coffee @@ -788,6 +788,21 @@ describe "EditorComponent", -> 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') + expect(lineNodes.length).toBe 13 + lineNode = lineNodes[0] + + wheelEvent = new WheelEvent('mousewheel', wheelDeltaX: 0, wheelDeltaY: 100) # goes nowhere, we're already at scrollTop 0 + Object.defineProperty(wheelEvent, 'target', get: -> lineNode) + node.dispatchEvent(wheelEvent) + + expect(component.mouseWheelScreenRow).toBe 0 + editor.insertText("hello") + expect(node.querySelectorAll('.line-number').length).toBe 14 # dummy line + expect(node.querySelectorAll('.line').length).toBe 13 + describe "when the mousewheel event's target is a line number", -> it "keeps the line number on the DOM if it is scrolled off-screen", -> node.style.height = 4.5 * lineHeightInPixels + 'px' diff --git a/src/editor-component.coffee b/src/editor-component.coffee index 0a1df0a5c..de2e40ddb 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -38,6 +38,7 @@ EditorComponent = React.createClass if @isMounted() renderedRowRange = @getRenderedRowRange() + [renderedStartRow, renderedEndRow] = renderedRowRange scrollHeight = editor.getScrollHeight() scrollWidth = editor.getScrollWidth() scrollTop = editor.getScrollTop() @@ -48,6 +49,8 @@ EditorComponent = React.createClass verticalScrollbarWidth = editor.getVerticalScrollbarWidth() verticallyScrollable = editor.verticallyScrollable() horizontallyScrollable = editor.horizontallyScrollable() + if @mouseWheelScreenRow? and not (renderedStartRow <= @mouseWheelScreenRow < renderedEndRow) + mouseWheelScreenRow = @mouseWheelScreenRow className = 'editor editor-colors react' className += ' is-focused' if focused @@ -56,7 +59,7 @@ EditorComponent = React.createClass GutterComponent { ref: 'gutter', editor, renderedRowRange, maxLineNumberDigits, scrollTop, scrollHeight, lineHeight, lineHeightInPixels, fontSize, fontFamily, - @pendingChanges, onWidthChanged: @onGutterWidthChanged, @mouseWheelScreenRow + @pendingChanges, onWidthChanged: @onGutterWidthChanged, mouseWheelScreenRow } EditorScrollViewComponent { @@ -64,7 +67,7 @@ EditorComponent = React.createClass lineHeight, lineHeightInPixels, renderedRowRange, @pendingChanges, scrollTop, scrollLeft, scrollHeight, scrollWidth, @scrollingVertically, @cursorsMoved, @selectionChanged, @selectionAdded, cursorBlinkPeriod, - cursorBlinkResumeDelay, @onInputFocused, @onInputBlurred, @mouseWheelScreenRow, + cursorBlinkResumeDelay, @onInputFocused, @onInputBlurred, mouseWheelScreenRow, invisibles, visible, scrollViewHeight, focused }