Skip to content

Commit

Permalink
Streamline character width remeasurement to hopefully avoid exceptions
Browse files Browse the repository at this point in the history
Previously, I was just remeasuring characters whenever the stylesheets
changed. I think there were situations in which the model changed, then
I remeasured characters prior to updating the view to match the model,
causing DOM exceptions. This switches the approach to only ever measure
characters after an update, ensuring the view always matches the model.
  • Loading branch information
Nathan Sobo committed Jul 8, 2014
1 parent 9975297 commit 1a22fc3
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/editor-component.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ EditorComponent = React.createClass
updateRequested: false
updatesPaused: false
updateRequestedWhilePaused: false
characterWidthRemeasurementRequested: false
cursorsMoved: false
selectionChanged: false
selectionAdded: false
Expand All @@ -43,7 +42,7 @@ EditorComponent = React.createClass
scrollSensitivity: 0.4
scrollViewMeasurementRequested: false
measureLineHeightAndDefaultCharWidthWhenShown: false
remeasureCharacterWidthsWhenShown: false
remeasureCharacterWidthsIfVisibleAfterNextUpdate: false
inputEnabled: true
scrollViewMeasurementInterval: 100
scopedCharacterWidthsChangeCount: null
Expand Down Expand Up @@ -655,7 +654,8 @@ EditorComponent = React.createClass

onStylesheetsChanged: (stylesheet) ->
@refreshScrollbars() if @containsScrollbarSelector(stylesheet)
@requestCharacterWidthRemeasurement()
@remeasureCharacterWidthsIfVisibleAfterNextUpdate = true
@requestUpdate() if @state.visible

onScreenLinesChanged: (change) ->
{editor} = @props
Expand Down Expand Up @@ -792,22 +792,12 @@ EditorComponent = React.createClass
if @state.visible
@remeasureCharacterWidths()
else
@remeasureCharacterWidthsWhenShown = true
else if @remeasureCharacterWidthsWhenShown and @state.visible and not prevState.visible
@remeasureCharacterWidthsIfVisibleAfterNextUpdate = true
else if @remeasureCharacterWidthsIfVisibleAfterNextUpdate and @state.visible
@remeasureCharacterWidthsIfVisibleAfterNextUpdate = false
@remeasureCharacterWidths()

requestCharacterWidthRemeasurement: ->
unless @characterWidthRemeasurementRequested
@characterWidthRemeasurementRequested = true
setImmediate =>
@characterWidthRemeasurementRequested = false
if @state.visible
@remeasureCharacterWidths()
else
@remeasureCharacterWidthsWhenShown = true

remeasureCharacterWidths: ->
@remeasureCharacterWidthsWhenShown = false
@refs.lines.remeasureCharacterWidths()

onGutterWidthChanged: (@gutterWidth) ->
Expand Down

0 comments on commit 1a22fc3

Please sign in to comment.