Merge pull request #3974 from atom/ns-throw-on-destroyed-editors

Throw on non-release builds if translating positions on destroyed editor
This commit is contained in:
Nathan Sobo
2014-10-27 11:32:48 -06:00
3 changed files with 17 additions and 6 deletions

View File

@@ -736,6 +736,10 @@ class DisplayBuffer extends Model
#
# Returns a {Point}.
screenPositionForBufferPosition: (bufferPosition, options) ->
# TODO: Expand this exception to cover all versions once we burn it in on non-release builds
if @isDestroyed() and not atom.isReleasedVersion()
throw new Error("This TextEditor has been destroyed")
{ row, column } = @buffer.clipPosition(bufferPosition)
[startScreenRow, endScreenRow] = @rowMap.screenRowRangeForBufferRow(row)
for screenRow in [startScreenRow...endScreenRow]
@@ -1073,7 +1077,7 @@ class DisplayBuffer extends Model
marker.notifyObservers(textChanged: false)
destroyed: ->
marker.unsubscribe() for marker in @getMarkers()
marker.unsubscribe() for id, marker of @markers
@tokenizedBuffer.destroy()
@unsubscribe()

View File

@@ -55,6 +55,8 @@ TextEditorComponent = React.createClass
hasSelection = editor.getLastSelection()? and !editor.getLastSelection().isEmpty()
style = {}
@performedInitialMeasurement = false if editor.isDestroyed()
if @performedInitialMeasurement
renderedRowRange = @getRenderedRowRange()
[renderedStartRow, renderedEndRow] = renderedRowRange
@@ -227,10 +229,10 @@ TextEditorComponent = React.createClass
@props.editor.setVisible(true)
@performedInitialMeasurement = true
@updatesPaused = false
@forceUpdate() if @updateRequestedWhilePaused
@forceUpdate() if @updateRequestedWhilePaused and @canUpdate()
requestUpdate: ->
return unless @isMounted()
return unless @canUpdate()
if @updatesPaused
@updateRequestedWhilePaused = true
@@ -242,7 +244,10 @@ TextEditorComponent = React.createClass
@updateRequested = true
requestAnimationFrame =>
@updateRequested = false
@forceUpdate() if @isMounted()
@forceUpdate() if @canUpdate()
canUpdate: ->
@isMounted() and @props.editor.isAlive()
requestAnimationFrame: (fn) ->
@updatesPaused = true
@@ -250,7 +255,7 @@ TextEditorComponent = React.createClass
requestAnimationFrame =>
fn()
@updatesPaused = false
if @updateRequestedWhilePaused and @isMounted()
if @updateRequestedWhilePaused and @canUpdate()
@updateRequestedWhilePaused = false
@forceUpdate()
@@ -773,7 +778,7 @@ TextEditorComponent = React.createClass
if position is 'absolute' or height
if @autoHeight
@autoHeight = false
@forceUpdate() unless @updatesPaused
@forceUpdate() if not @updatesPaused and @canUpdate()
clientHeight = scrollViewNode.clientHeight
editor.setHeight(clientHeight) if clientHeight > 0

View File

@@ -37,6 +37,8 @@ class TextEditorElement extends HTMLElement
setModel: (model) ->
throw new Error("Model already assigned on TextEditorElement") if @model?
return if model.isDestroyed()
@model = model
@mountComponent()
@addGrammarScopeAttribute()