From 9be593d390389c128a25731482181d992d7d98c0 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 20 Mar 2014 15:22:16 -0600 Subject: [PATCH 1/2] Eliminate options object for suppressAutoscroll It's a single option used only internally. Let's not allocate an object for it. --- src/editor-view.coffee | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/editor-view.coffee b/src/editor-view.coffee index 02f627d15..949c35fe8 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -940,7 +940,7 @@ class EditorView extends View @setSoftWrap(@editor.getSoftWrap()) @newCursors = @editor.getCursors() @newSelections = @editor.getSelections() - @updateDisplay(suppressAutoScroll: true) + @updateDisplay(suppressAutoscroll: true) requestDisplayUpdate: -> return if @pendingDisplayUpdate @@ -950,7 +950,7 @@ class EditorView extends View @updateDisplay() @pendingDisplayUpdate = false - updateDisplay: (options={}) -> + updateDisplay: (options) -> return unless @attached and @editor return if @editor.isDestroyed() unless @isOnDom() and @isVisible() @@ -962,7 +962,7 @@ class EditorView extends View @highlightCursorLine() @updateCursorViews() @updateSelectionViews() - @autoscroll(options) + @autoscroll(options?.suppressAutoscroll ? false) @trigger 'editor:display-updated' updateCursorViews: -> @@ -1005,14 +1005,14 @@ class EditorView extends View syncCursorAnimations: -> cursorView.resetBlinking() for cursorView in @getCursorViews() - autoscroll: (options={}) -> + autoscroll: (suppressAutoscroll) -> for cursorView in @getCursorViews() - if !options.suppressAutoScroll and cursorView.needsAutoscroll() + if !suppressAutoscroll and cursorView.needsAutoscroll() @scrollToPixelPosition(cursorView.getPixelPosition()) cursorView.clearAutoscroll() for selectionView in @getSelectionViews() - if !options.suppressAutoScroll and selectionView.needsAutoscroll() + if !suppressAutoscroll and selectionView.needsAutoscroll() @scrollToPixelPosition(selectionView.getCenterPixelPosition(), center: true) selectionView.highlight() selectionView.clearAutoscroll() From 50c25d9e443e1d2b710ecc71f53f8d7aeed3f240 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 20 Mar 2014 15:45:12 -0600 Subject: [PATCH 2/2] Read scrollView width prior to touching the DOM to prevent reflow --- src/editor-view.coffee | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/editor-view.coffee b/src/editor-view.coffee index 949c35fe8..075284019 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -896,7 +896,7 @@ class EditorView extends View @clearCharacterWidthCache() @requestDisplayUpdate() - updateLayerDimensions: -> + updateLayerDimensions: (scrollViewWidth) -> height = @lineHeight * @editor.getScreenLineCount() unless @layerHeight == height @layerHeight = height @@ -906,7 +906,7 @@ class EditorView extends View @verticalScrollbarContent.height(@layerHeight) @scrollBottom(height) if @scrollBottom() > height - minWidth = Math.max(@charWidth * @editor.getMaxScreenLineLength() + 20, @scrollView.width()) + minWidth = Math.max(@charWidth * @editor.getMaxScreenLineLength() + 20, scrollViewWidth) unless @layerMinWidth == minWidth @renderedLines.css('min-width', minWidth) @underlayer.css('min-width', minWidth) @@ -957,7 +957,8 @@ class EditorView extends View @redrawOnReattach = true return - @updateRenderedLines() + scrollViewWidth = @scrollView.width() + @updateRenderedLines(scrollViewWidth) @updatePlaceholderText() @highlightCursorLine() @updateCursorViews() @@ -1028,7 +1029,7 @@ class EditorView extends View else @underlayer.append($('', class: 'placeholder-text', text: @placeholderText)) - updateRenderedLines: -> + updateRenderedLines: (scrollViewWidth) -> firstVisibleScreenRow = @getFirstVisibleScreenRow() lastScreenRowToRender = firstVisibleScreenRow + @heightInLines - 1 lastScreenRow = @editor.getLastScreenRow() @@ -1052,7 +1053,7 @@ class EditorView extends View @fillDirtyRanges(intactRanges, renderFrom, renderTo) @firstRenderedScreenRow = renderFrom @lastRenderedScreenRow = renderTo - @updateLayerDimensions() + @updateLayerDimensions(scrollViewWidth) @updatePaddingOfRenderedLines() computeSurroundingEmptyLineChanges: (change) ->