From 72093da1a7a6513bacff388df4488a28627e9e77 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 29 Sep 2015 17:32:20 +0200 Subject: [PATCH] :fire: :tada: Remove scoped character width --- src/display-buffer.coffee | 30 ------------ src/lines-component.coffee | 19 -------- src/lines-tile-component.coffee | 82 -------------------------------- src/text-editor-component.coffee | 16 +------ src/text-editor-presenter.coffee | 29 ----------- 5 files changed, 2 insertions(+), 174 deletions(-) diff --git a/src/display-buffer.coffee b/src/display-buffer.coffee index 27d1b44cf..339fa11c1 100644 --- a/src/display-buffer.coffee +++ b/src/display-buffer.coffee @@ -18,7 +18,6 @@ module.exports = class DisplayBuffer extends Model verticalScrollMargin: 2 horizontalScrollMargin: 6 - scopedCharacterWidthsChangeCount: 0 changeCount: 0 softWrapped: null editorWidthInChars: null @@ -198,35 +197,6 @@ class DisplayBuffer extends Model getCursorWidth: -> 1 - getScopedCharWidth: (scopeNames, char) -> - @getScopedCharWidths(scopeNames)[char] - - getScopedCharWidths: (scopeNames) -> - scope = @charWidthsByScope - for scopeName in scopeNames - scope[scopeName] ?= {} - scope = scope[scopeName] - scope.charWidths ?= {} - scope.charWidths - - batchCharacterMeasurement: (fn) -> - oldChangeCount = @scopedCharacterWidthsChangeCount - @batchingCharacterMeasurement = true - fn() - @batchingCharacterMeasurement = false - @characterWidthsChanged() if oldChangeCount isnt @scopedCharacterWidthsChangeCount - - setScopedCharWidth: (scopeNames, char, width) -> - @getScopedCharWidths(scopeNames)[char] = width - @scopedCharacterWidthsChangeCount++ - @characterWidthsChanged() unless @batchingCharacterMeasurement - - characterWidthsChanged: -> - @emitter.emit 'did-change-character-widths', @scopedCharacterWidthsChangeCount - - clearScopedCharWidths: -> - @charWidthsByScope = {} - scrollToScreenRange: (screenRange, options = {}) -> scrollEvent = {screenRange, options} @emitter.emit "did-request-autoscroll", scrollEvent diff --git a/src/lines-component.coffee b/src/lines-component.coffee index 422729135..3cd9215a6 100644 --- a/src/lines-component.coffee +++ b/src/lines-component.coffee @@ -82,25 +82,6 @@ class LinesComponent extends TiledComponent @presenter.setLineHeight(lineHeightInPixels) @presenter.setBaseCharacterWidth(charWidth) - remeasureCharacterWidths: -> - return unless @presenter.baseCharacterWidth - - @clearScopedCharWidths() - @measureCharactersInNewLines() - - measureCharactersInNewLines: -> - @presenter.batchCharacterMeasurement => - for id, component of @componentsByTileId - component.measureCharactersInNewLines() - - return - - clearScopedCharWidths: -> - for id, component of @componentsByTileId - component.clearMeasurements() - - @presenter.clearScopedCharacterWidths() - lineNodeForLineIdAndScreenRow: (lineId, screenRow) -> tile = @presenter.tileForRow(screenRow) @getComponentForTile(tile)?.lineNodeForLineId(lineId) diff --git a/src/lines-tile-component.coffee b/src/lines-tile-component.coffee index 3c70c1199..4b18af3bb 100644 --- a/src/lines-tile-component.coffee +++ b/src/lines-tile-component.coffee @@ -317,85 +317,3 @@ class LinesTileComponent lineNodeForLineId: (lineId) -> @lineNodesByLineId[lineId] - - measureCharactersInNewLines: -> - for id, lineState of @oldTileState.lines - unless @measuredLines.has(id) - lineNode = @lineNodesByLineId[id] - @measureCharactersInLine(id, lineState, lineNode) - return - - measureCharactersInLine: (lineId, tokenizedLine, lineNode) -> - rangeForMeasurement = null - iterator = null - charIndex = 0 - - @tokenIterator.reset(tokenizedLine) - while @tokenIterator.next() - scopes = @tokenIterator.getScopes() - text = @tokenIterator.getText() - charWidths = @presenter.getScopedCharacterWidths(scopes) - - textIndex = 0 - while textIndex < text.length - if @tokenIterator.isPairedCharacter() - char = text - charLength = 2 - textIndex += 2 - else - char = text[textIndex] - charLength = 1 - textIndex++ - - unless charWidths[char]? - unless textNode? - rangeForMeasurement ?= document.createRange() - iterator = document.createNodeIterator(lineNode, NodeFilter.SHOW_TEXT, AcceptFilter) - textNode = iterator.nextNode() - textNodeLength = textNode.textContent.length - textNodeIndex = 0 - nextTextNodeIndex = textNodeLength - - while nextTextNodeIndex <= charIndex - textNode = iterator.nextNode() - textNodeLength = textNode.textContent.length - textNodeIndex = nextTextNodeIndex - nextTextNodeIndex = textNodeIndex + textNodeLength - - i = charIndex - textNodeIndex - rangeForMeasurement.setStart(textNode, i) - - if i + charLength <= textNodeLength - rangeForMeasurement.setEnd(textNode, i + charLength) - else - rangeForMeasurement.setEnd(textNode, textNodeLength) - atom.assert false, "Expected index to be less than the length of text node while measuring", (error) => - editor = @presenter.model - screenRow = tokenizedLine.screenRow - bufferRow = editor.bufferRowForScreenRow(screenRow) - - error.metadata = { - grammarScopeName: editor.getGrammar().scopeName - screenRow: screenRow - bufferRow: bufferRow - softWrapped: editor.isSoftWrapped() - softTabs: editor.getSoftTabs() - i: i - charLength: charLength - textNodeLength: textNode.length - } - error.privateMetadataDescription = "The contents of line #{bufferRow + 1}." - error.privateMetadata = { - lineText: editor.lineTextForBufferRow(bufferRow) - } - error.privateMetadataRequestName = "measured-line-text" - - charWidth = rangeForMeasurement.getBoundingClientRect().width - @presenter.setScopedCharacterWidth(scopes, char, charWidth) - - charIndex += charLength - - @measuredLines.add(lineId) - - clearMeasurements: -> - @measuredLines.clear() diff --git a/src/text-editor-component.coffee b/src/text-editor-component.coffee index 8ed17fb1b..b9535b2aa 100644 --- a/src/text-editor-component.coffee +++ b/src/text-editor-component.coffee @@ -30,7 +30,6 @@ class TextEditorComponent inputEnabled: true measureScrollbarsWhenShown: true measureLineHeightAndDefaultCharWidthWhenShown: true - remeasureCharacterWidthsWhenShown: false stylingChangeAnimationFrameRequested: false gutterComponent: null mounted: true @@ -169,7 +168,6 @@ class TextEditorComponent @updateParentViewMiniClass() readAfterUpdateSync: => - @linesComponent.measureCharactersInNewLines() if @isVisible() and not @newState.content.scrollingVertically @overlayManager?.measureOverlays() mountGutterContainerComponent: -> @@ -184,7 +182,6 @@ class TextEditorComponent @measureWindowSize() @measureDimensions() @measureLineHeightAndDefaultCharWidth() if @measureLineHeightAndDefaultCharWidthWhenShown - @remeasureCharacterWidths() if @remeasureCharacterWidthsWhenShown @editor.setVisible(true) @performedInitialMeasurement = true @updatesPaused = false @@ -563,7 +560,6 @@ class TextEditorComponent handleStylingChange: => @sampleFontStyling() @sampleBackgroundColors() - @remeasureCharacterWidths() handleDragUntilMouseUp: (dragHandler) => dragging = false @@ -712,15 +708,14 @@ class TextEditorComponent oldFontFamily = @fontFamily oldLineHeight = @lineHeight + @presenter.characterWidthsChanged() + {@fontSize, @fontFamily, @lineHeight} = getComputedStyle(@getTopmostDOMNode()) if @fontSize isnt oldFontSize or @fontFamily isnt oldFontFamily or @lineHeight isnt oldLineHeight @clearPoolAfterUpdate = true @measureLineHeightAndDefaultCharWidth() - if (@fontSize isnt oldFontSize or @fontFamily isnt oldFontFamily) and @performedInitialMeasurement - @remeasureCharacterWidths() - sampleBackgroundColors: (suppressUpdate) -> {backgroundColor} = getComputedStyle(@hostElement) @@ -738,13 +733,6 @@ class TextEditorComponent else @measureLineHeightAndDefaultCharWidthWhenShown = true - remeasureCharacterWidths: -> - if @isVisible() - @remeasureCharacterWidthsWhenShown = false - @linesComponent.remeasureCharacterWidths() - else - @remeasureCharacterWidthsWhenShown = true - measureScrollbars: -> @measureScrollbarsWhenShown = false diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 39b51063c..f9166ace9 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -9,7 +9,6 @@ class TextEditorPresenter startBlinkingCursorsAfterDelay: null stoppedScrollingTimeoutId: null mouseWheelScreenRow: null - scopedCharacterWidthsChangeCount: 0 overlayDimensions: {} minimumReflowInterval: 200 @@ -1089,30 +1088,6 @@ class TextEditorPresenter @model.setDefaultCharWidth(baseCharacterWidth) @characterWidthsChanged() - getScopedCharacterWidth: (scopeNames, char) -> - @getScopedCharacterWidths(scopeNames)[char] - - getScopedCharacterWidths: (scopeNames) -> - scope = @characterWidthsByScope - for scopeName in scopeNames - scope[scopeName] ?= {} - scope = scope[scopeName] - scope.characterWidths ?= {} - scope.characterWidths - - batchCharacterMeasurement: (fn) -> - oldChangeCount = @scopedCharacterWidthsChangeCount - @batchingCharacterMeasurement = true - @model.batchCharacterMeasurement(fn) - @batchingCharacterMeasurement = false - @characterWidthsChanged() if oldChangeCount isnt @scopedCharacterWidthsChangeCount - - setScopedCharacterWidth: (scopeNames, character, width) -> - @getScopedCharacterWidths(scopeNames)[character] = width - @model.setScopedCharWidth(scopeNames, character, width) - @scopedCharacterWidthsChangeCount++ - @characterWidthsChanged() unless @batchingCharacterMeasurement - characterWidthsChanged: -> @shouldUpdateHorizontalScrollState = true @shouldUpdateVerticalScrollState = true @@ -1126,10 +1101,6 @@ class TextEditorPresenter @emitDidUpdateState() - clearScopedCharacterWidths: -> - @characterWidthsByScope = {} - @model.clearScopedCharWidths() - hasPixelPositionRequirements: -> @lineHeight? and @baseCharacterWidth?