mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Batch together line and character width measurement after font changes
This ensures we only perform a single update with the most up-to-date information about line height, default character width, and specific character widths. If this update causes more lines to be drawn we may measure again, but not necessarily.
This commit is contained in:
@@ -35,7 +35,7 @@ EditorComponent = React.createClass
|
||||
scrollViewMeasurementRequested: false
|
||||
overflowChangedEventsPaused: false
|
||||
overflowChangedWhilePaused: false
|
||||
measureLineHeightInPixelsAndCharWidthWhenShown: false
|
||||
measureLineHeightAndDefaultCharWidthWhenShown: false
|
||||
|
||||
render: ->
|
||||
{focused, fontSize, lineHeight, fontFamily, showIndentGuide, showInvisibles, visible} = @state
|
||||
@@ -140,17 +140,21 @@ EditorComponent = React.createClass
|
||||
@observeConfig()
|
||||
|
||||
componentDidMount: ->
|
||||
{editor} = @props
|
||||
|
||||
@observeEditor()
|
||||
@listenForDOMEvents()
|
||||
@listenForCommands()
|
||||
@measureScrollbars()
|
||||
|
||||
@subscribe atom.themes, 'stylesheet-added stylsheet-removed', @onStylesheetsChanged
|
||||
@subscribe scrollbarStyle.changes, @refreshScrollbars
|
||||
@props.editor.setVisible(true)
|
||||
|
||||
@measureScrollView()
|
||||
editor.setVisible(true)
|
||||
|
||||
@requestUpdate()
|
||||
editor.batchUpdates =>
|
||||
@measureLineHeightAndDefaultCharWidth()
|
||||
@measureScrollView()
|
||||
@measureScrollbars()
|
||||
|
||||
componentWillUnmount: ->
|
||||
@unsubscribe()
|
||||
@@ -163,11 +167,7 @@ EditorComponent = React.createClass
|
||||
@pendingChanges.length = 0
|
||||
@refreshingScrollbars = false
|
||||
@measureScrollbars() if @measuringScrollbars
|
||||
@measureLineHeightInPixelsAndCharWidthIfNeeded(prevState)
|
||||
unless isEqualForProperties(prevState, @state, 'fontSize', 'fontFamily')
|
||||
@refs.lines.clearScopedCharWidths()
|
||||
@refs.lines.measureCharactersInNewLines()
|
||||
|
||||
@measureLineHeightAndCharWidthsIfNeeded(prevState)
|
||||
@pauseOverflowChangedEvents()
|
||||
@props.parentView.trigger 'editor:display-updated'
|
||||
|
||||
@@ -573,20 +573,24 @@ EditorComponent = React.createClass
|
||||
clientWidth = scrollViewNode.clientWidth
|
||||
editor.setWidth(clientWidth) if clientWidth > 0
|
||||
|
||||
measureLineHeightInPixelsAndCharWidthIfNeeded: (prevState) ->
|
||||
unless isEqualForProperties(prevState, @state, 'lineHeight', 'fontSize', 'fontFamily')
|
||||
if @state.visible
|
||||
@measureLineHeightInPixelsAndCharWidth()
|
||||
else
|
||||
@measureLineHeightInPixelsAndCharWidthWhenShown = true
|
||||
return
|
||||
measureLineHeightAndCharWidthsIfNeeded: (prevState) ->
|
||||
if not isEqualForProperties(prevState, @state, 'lineHeight', 'fontSize', 'fontFamily')
|
||||
@props.editor.batchUpdates =>
|
||||
if @state.visible
|
||||
@measureLineHeightAndDefaultCharWidth()
|
||||
else
|
||||
@measureLineHeightAndDefaultCharWidthWhenShown = true
|
||||
|
||||
if @measureLineHeightInPixelsAndCharWidthWhenShown and @state.visible and not prevState.visible
|
||||
@measureLineHeightInPixelsAndCharWidth()
|
||||
unless isEqualForProperties(prevState, @state, 'fontSize', 'fontFamily')
|
||||
@refs.lines.clearScopedCharWidths()
|
||||
@refs.lines.measureCharactersInNewLines()
|
||||
|
||||
measureLineHeightInPixelsAndCharWidth: ->
|
||||
@measureLineHeightInPixelsAndCharWidthWhenShown = false
|
||||
@refs.lines.measureLineHeightInPixelsAndCharWidth()
|
||||
else if @measureLineHeightAndDefaultCharWidthWhenShown and @state.visible and not prevState.visible
|
||||
@measureLineHeightAndDefaultCharWidth()
|
||||
|
||||
measureLineHeightAndDefaultCharWidth: ->
|
||||
@measureLineHeightAndDefaultCharWidthWhenShown = false
|
||||
@refs.lines.measureLineHeightAndDefaultCharWidth()
|
||||
|
||||
measureScrollbars: ->
|
||||
@measuringScrollbars = false
|
||||
|
||||
@@ -30,9 +30,6 @@ LinesComponent = React.createClass
|
||||
@screenRowsByLineId = {}
|
||||
@lineIdsByScreenRow = {}
|
||||
|
||||
componentDidMount: ->
|
||||
@measureLineHeightInPixelsAndCharWidth()
|
||||
|
||||
shouldComponentUpdate: (newProps) ->
|
||||
return true unless isEqualForProperties(newProps, @props,
|
||||
'renderedRowRange', 'selectionScreenRanges', 'lineHeightInPixels', 'defaultCharWidth',
|
||||
@@ -200,8 +197,7 @@ LinesComponent = React.createClass
|
||||
lineNodeForScreenRow: (screenRow) ->
|
||||
@lineNodesByLineId[@lineIdsByScreenRow[screenRow]]
|
||||
|
||||
measureLineHeightInPixelsAndCharWidth: ->
|
||||
@measureWhenShown = false
|
||||
measureLineHeightAndDefaultCharWidth: ->
|
||||
node = @getDOMNode()
|
||||
node.appendChild(DummyLineNode)
|
||||
lineHeightInPixels = DummyLineNode.getBoundingClientRect().height
|
||||
@@ -209,8 +205,9 @@ LinesComponent = React.createClass
|
||||
node.removeChild(DummyLineNode)
|
||||
|
||||
{editor} = @props
|
||||
editor.setLineHeightInPixels(lineHeightInPixels)
|
||||
editor.setDefaultCharWidth(charWidth)
|
||||
editor.batchUpdates ->
|
||||
editor.setLineHeightInPixels(lineHeightInPixels)
|
||||
editor.setDefaultCharWidth(charWidth)
|
||||
|
||||
measureCharactersInNewLines: ->
|
||||
[visibleStartRow, visibleEndRow] = @props.renderedRowRange
|
||||
|
||||
Reference in New Issue
Block a user