Construct TextEditorPresenter before component mounts

This allows us to use the presenter for all stages of the component
lifecycle rather than needing to wait until it is created.

Signed-off-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
Esse commit está contido em:
Nathan Sobo
2015-01-27 17:27:59 -07:00
commit fd50a0db6c
5 arquivos alterados com 42 adições e 56 exclusões
+2 -2
Ver Arquivo
@@ -12,9 +12,9 @@ CursorsComponent = React.createClass
{presenter} = @props
className = 'cursors'
className += ' blink-off' if presenter?.state.content.blinkCursorsOff
className += ' blink-off' if presenter.state.content.blinkCursorsOff
div {className},
if presenter?
if presenter.hasRequiredMeasurements()
for key, pixelRect of presenter.state.content.cursors
CursorComponent({key, pixelRect})
+4 -6
Ver Arquivo
@@ -21,9 +21,9 @@ GutterComponent = React.createClass
div className: 'gutter',
div className: 'line-numbers', ref: 'lineNumbers', style:
height: presenter?.state.scrollHeight
WebkitTransform: @getTransform() if presenter?
backgroundColor: presenter?.state.gutter.backgroundColor
height: presenter.state.scrollHeight
WebkitTransform: @getTransform() if presenter.hasRequiredMeasurements()
backgroundColor: presenter.state.gutter.backgroundColor
getTransform: ->
{presenter, useHardwareAcceleration} = @props
@@ -39,15 +39,13 @@ GutterComponent = React.createClass
componentDidMount: ->
@appendDummyLineNumber()
@updateLineNumbers() if @props.presenter?
@updateLineNumbers()
node = @getDOMNode()
node.addEventListener 'click', @onClick
node.addEventListener 'mousedown', @onMouseDown
componentDidUpdate: (oldProps) ->
return unless @props.presenter?
unless isEqualForProperties(oldProps, @props, 'maxLineNumberDigits')
@updateDummyLineNumber()
node.remove() for id, node of @lineNumberNodesById
+1 -1
Ver Arquivo
@@ -9,7 +9,7 @@ HighlightsComponent = React.createClass
render: ->
div className: 'highlights',
@renderHighlights() if @props.presenter?
@renderHighlights()
renderHighlights: ->
{presenter} = @props
+13 -18
Ver Arquivo
@@ -17,25 +17,21 @@ LinesComponent = React.createClass
displayName: 'LinesComponent'
render: ->
{presenter} = @props
{editor, presenter} = @props
@oldState ?= {content: {lines: {}}}
@newState = presenter.state
if presenter?
{editor, presenter} = @props
{scrollHeight} = @newState
{scrollWidth, backgroundColor, placeholderText} = @newState.content
@oldState ?= {content: {lines: {}}}
@newState = presenter.state
{scrollHeight} = @newState
{scrollWidth, backgroundColor, placeholderText} = @newState.content
style =
height: scrollHeight
width: scrollWidth
WebkitTransform: @getTransform()
backgroundColor: backgroundColor
style =
height: scrollHeight
width: scrollWidth
WebkitTransform: @getTransform()
backgroundColor: backgroundColor
div {className: 'lines', style},
div className: 'placeholder-text', placeholderText if placeholderText?
CursorsComponent {presenter}
HighlightsComponent {presenter}
@@ -71,7 +67,6 @@ LinesComponent = React.createClass
componentDidUpdate: ->
{visible, presenter} = @props
return unless presenter?
@removeLineNodes() unless @oldState?.content.indentGuidesVisible is @newState?.content.indentGuidesVisible
@updateLineNodes()
@@ -261,13 +256,13 @@ LinesComponent = React.createClass
node.removeChild(DummyLineNode)
{editor, presenter} = @props
presenter?.setLineHeight(lineHeightInPixels)
presenter.setLineHeight(lineHeightInPixels)
editor.setLineHeightInPixels(lineHeightInPixels)
presenter?.setBaseCharacterWidth(charWidth)
presenter.setBaseCharacterWidth(charWidth)
editor.setDefaultCharWidth(charWidth)
remeasureCharacterWidths: ->
return unless @props.presenter?
return unless @props.presenter.hasRequiredMeasurements()
@clearScopedCharWidths()
@measureCharactersInNewLines()
+22 -29
Ver Arquivo
@@ -147,6 +147,19 @@ TextEditorComponent = React.createClass
@observeConfig()
@setScrollSensitivity(atom.config.get('editor.scrollSensitivity'))
{editor, lineOverdrawMargin, cursorBlinkPeriod, cursorBlinkResumeDelay} = @props
@presenter = new TextEditorPresenter
model: editor
scrollTop: editor.getScrollTop()
scrollLeft: editor.getScrollLeft()
lineOverdrawMargin: lineOverdrawMargin
cursorBlinkPeriod: cursorBlinkPeriod
cursorBlinkResumeDelay: cursorBlinkResumeDelay
stoppedScrollingDelay: 200
@presenter.onDidUpdateState(@requestUpdate)
componentDidMount: ->
{editor, stylesElement} = @props
@@ -198,26 +211,6 @@ TextEditorComponent = React.createClass
@props.editor.setVisible(true)
@performedInitialMeasurement = true
@updatesPaused = false
{editor, lineOverdrawMargin, cursorBlinkPeriod, cursorBlinkResumeDelay} = @props
unless @presenter?
@presenter = new TextEditorPresenter
model: editor
clientHeight: editor.getHeight()
clientWidth: editor.getWidth()
scrollTop: editor.getScrollTop()
scrollLeft: editor.getScrollLeft()
lineHeight: editor.getLineHeightInPixels()
baseCharacterWidth: editor.getDefaultCharWidth()
lineOverdrawMargin: lineOverdrawMargin
cursorBlinkPeriod: cursorBlinkPeriod
cursorBlinkResumeDelay: cursorBlinkResumeDelay
stoppedScrollingDelay: 200
backgroundColor: @backgroundColor
gutterBackgroundColor: @gutterBackgroundColor
@presenter.onDidUpdateState(@requestUpdate)
@forceUpdate() if @canUpdate()
requestUpdate: ->
@@ -407,7 +400,7 @@ TextEditorComponent = React.createClass
@requestAnimationFrame =>
pendingScrollTop = @pendingScrollTop
@pendingScrollTop = null
@presenter?.setScrollTop(pendingScrollTop)
@presenter.setScrollTop(pendingScrollTop)
@props.editor.setScrollTop(pendingScrollTop)
onHorizontalScroll: (scrollLeft) ->
@@ -420,7 +413,7 @@ TextEditorComponent = React.createClass
unless animationFramePending
@requestAnimationFrame =>
@props.editor.setScrollLeft(@pendingScrollLeft)
@presenter?.setScrollLeft(@pendingScrollLeft)
@presenter.setScrollLeft(@pendingScrollLeft)
@pendingScrollLeft = null
onMouseWheel: (event) ->
@@ -609,13 +602,13 @@ TextEditorComponent = React.createClass
@requestUpdate()
onScrollTopChanged: ->
@presenter?.setScrollTop(@props.editor.getScrollTop())
@presenter.setScrollTop(@props.editor.getScrollTop())
@requestUpdate()
@onStoppedScrollingAfterDelay ?= debounce(@onStoppedScrolling, 200)
@onStoppedScrollingAfterDelay()
onScrollLeftChanged: ->
@presenter?.setScrollLeft(@props.editor.getScrollLeft())
@presenter.setScrollLeft(@props.editor.getScrollLeft())
@requestUpdate()
onStoppedScrolling: ->
@@ -749,10 +742,10 @@ TextEditorComponent = React.createClass
clientHeight = scrollViewNode.clientHeight
if clientHeight > 0
@presenter?.setClientHeight(clientHeight)
@presenter.setClientHeight(clientHeight)
editor.setHeight(clientHeight)
else
@presenter?.setClientHeight(null)
@presenter.setClientHeight(null)
editor.setHeight(null)
@autoHeight = true
@@ -760,7 +753,7 @@ TextEditorComponent = React.createClass
paddingLeft = parseInt(getComputedStyle(scrollViewNode).paddingLeft)
clientWidth -= paddingLeft
if clientWidth > 0
@presenter?.setClientWidth(clientWidth)
@presenter.setClientWidth(clientWidth)
editor.setWidth(clientWidth)
sampleFontStyling: ->
@@ -782,13 +775,13 @@ TextEditorComponent = React.createClass
if backgroundColor isnt @backgroundColor
@backgroundColor = backgroundColor
@presenter?.setBackgroundColor(backgroundColor)
@presenter.setBackgroundColor(backgroundColor)
if @refs.gutter?
gutterBackgroundColor = getComputedStyle(@refs.gutter.getDOMNode()).backgroundColor
if gutterBackgroundColor isnt @gutterBackgroundColor
@gutterBackgroundColor = gutterBackgroundColor
@presenter?.setGutterBackgroundColor(gutterBackgroundColor)
@presenter.setGutterBackgroundColor(gutterBackgroundColor)
@requestUpdate() unless suppressUpdate
measureLineHeightAndDefaultCharWidth: ->