🔥 🎉 Remove scoped character width

This commit is contained in:
Antonio Scandurra
2015-09-29 17:32:20 +02:00
parent 123594dbbf
commit 72093da1a7
5 changed files with 2 additions and 174 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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()

View File

@@ -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

View File

@@ -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?