mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
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:
@@ -69,7 +69,7 @@ GutterComponent = React.createClass
|
||||
@dummyLineNumberNode.innerHTML = @buildLineNumberInnerHTML(0, false)
|
||||
|
||||
updateLineNumbers: ->
|
||||
{presenter, mouseWheelScreenRow} = @props
|
||||
{presenter} = @props
|
||||
@oldState ?= {lineNumbers: {}}
|
||||
newState = presenter.state.gutter
|
||||
newLineNumberIds = null
|
||||
@@ -96,7 +96,7 @@ GutterComponent = React.createClass
|
||||
node.appendChild(lineNumberNode)
|
||||
|
||||
for id, lineNumberState of @oldState.lineNumbers
|
||||
unless newState.lineNumbers.hasOwnProperty(id) or lineNumberState.screenRow is mouseWheelScreenRow
|
||||
unless newState.lineNumbers.hasOwnProperty(id)
|
||||
@lineNumberNodesById[id].remove()
|
||||
delete @lineNumberNodesById[id]
|
||||
delete @oldState.lineNumbers[id]
|
||||
|
||||
@@ -92,10 +92,10 @@ LinesComponent = React.createClass
|
||||
delete @oldState.content.lines[id]
|
||||
|
||||
updateLineNodes: ->
|
||||
{presenter, mouseWheelScreenRow} = @props
|
||||
{presenter} = @props
|
||||
|
||||
for id of @oldState.content.lines
|
||||
unless @newState.content.lines.hasOwnProperty(id) or mouseWheelScreenRow is @screenRowsByLineId[id]
|
||||
unless @newState.content.lines.hasOwnProperty(id)
|
||||
@removeLineNode(id)
|
||||
|
||||
newLineIds = null
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ class TextEditorPresenter
|
||||
toggleCursorBlinkHandle: null
|
||||
startBlinkingCursorsAfterDelay: null
|
||||
stoppedScrollingTimeoutId: null
|
||||
mouseWheelScreenRow: null
|
||||
|
||||
constructor: (params) ->
|
||||
{@model, @clientHeight, @clientWidth, @scrollTop, @scrollLeft} = params
|
||||
|
||||
Reference in New Issue
Block a user