Handle line and line number preservation in presenter

The target of mousewheel events needs to be preserved when scrolling.
It used to be dealt with in the view, but now we can do it in the
presenter for a simpler view implementation.
This commit is contained in:
Nathan Sobo
2015-01-28 16:55:49 -07:00
parent d9a5d141eb
commit 76241fb779
5 changed files with 13 additions and 28 deletions

View File

@@ -31,8 +31,6 @@ TextEditorComponent = React.createClass
updateRequestedWhilePaused: false
cursorMoved: false
selectionChanged: false
mouseWheelScreenRow: null
mouseWheelScreenRowClearDelay: 150
scrollSensitivity: 0.4
heightAndWidthMeasurementRequested: false
inputEnabled: true
@@ -66,8 +64,6 @@ TextEditorComponent = React.createClass
horizontallyScrollable = editor.horizontallyScrollable()
hiddenInputStyle = @getHiddenInputPosition()
hiddenInputStyle.WebkitTransform = 'translateZ(0)' if @useHardwareAcceleration
if @mouseWheelScreenRow? and not (renderedStartRow <= @mouseWheelScreenRow < renderedEndRow)
mouseWheelScreenRow = @mouseWheelScreenRow
style.height = scrollHeight if @autoHeight
@@ -82,7 +78,7 @@ TextEditorComponent = React.createClass
if @gutterVisible
GutterComponent {
ref: 'gutter', onMouseDown: @onGutterMouseDown,
@presenter, editor, mouseWheelScreenRow, @useHardwareAcceleration
@presenter, editor, @useHardwareAcceleration
}
div ref: 'scrollView', className: 'scroll-view',
@@ -92,8 +88,7 @@ TextEditorComponent = React.createClass
style: hiddenInputStyle
LinesComponent {
ref: 'lines', @presenter, editor, hostElement, @useHardwareAcceleration, useShadowDOM,
mouseWheelScreenRow, visible
ref: 'lines', @presenter, editor, hostElement, @useHardwareAcceleration, useShadowDOM, visible
}
ScrollbarComponent
@@ -433,9 +428,7 @@ TextEditorComponent = React.createClass
event.preventDefault() unless previousScrollLeft is editor.getScrollLeft()
else
# Scrolling vertically
@mouseWheelScreenRow = @screenRowForNode(event.target)
@clearMouseWheelScreenRowAfterDelay ?= debounce(@clearMouseWheelScreenRow, @mouseWheelScreenRowClearDelay)
@clearMouseWheelScreenRowAfterDelay()
@presenter.setMouseWheelScreenRow(@screenRowForNode(event.target))
previousScrollTop = editor.getScrollTop()
editor.setScrollTop(previousScrollTop - Math.round(wheelDeltaY * @scrollSensitivity))
event.preventDefault() unless previousScrollTop is editor.getScrollTop()
@@ -846,13 +839,6 @@ TextEditorComponent = React.createClass
horizontalNode.style.display = originalHorizontalDisplayValue
cornerNode.style.display = originalCornerDisplayValue
clearMouseWheelScreenRow: ->
if @mouseWheelScreenRow?
@mouseWheelScreenRow = null
@requestUpdate()
clearMouseWheelScreenRowAfterDelay: null # created lazily
consolidateSelections: (e) ->
e.abortKeyBinding() unless @props.editor.consolidateSelections()