mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-21 07:58:04 +03:00
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.
This commit is contained in:
parent
89c57b6d52
commit
0043072ecf
@ -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'
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user