mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Handle tab length retokenization in DisplayLayer
We still want to keep the tab length in TokenizedBuffer, because we need it to understand if a certain buffer row is foldable or not (due to the indent level)
This commit is contained in:
@@ -122,7 +122,7 @@ class DisplayBuffer extends Model
|
||||
invisibles: invisibles
|
||||
softWrapColumn: softWrapColumn
|
||||
showIndentGuides: @config.get('editor.showIndentGuide', scope: scopeDescriptor)
|
||||
tabLength: @config.get('editor.tabLength', scope: scopeDescriptor),
|
||||
tabLength: @getTabLength(),
|
||||
ratioForCharacter: @ratioForCharacter.bind(this)
|
||||
isWrapBoundary: isWrapBoundary
|
||||
})
|
||||
@@ -265,13 +265,20 @@ class DisplayBuffer extends Model
|
||||
#
|
||||
# Returns a {Number}.
|
||||
getTabLength: ->
|
||||
@tokenizedBuffer.getTabLength()
|
||||
if @tabLength?
|
||||
@tabLength
|
||||
else
|
||||
@config.get('editor.tabLength', scope: @getRootScopeDescriptor())
|
||||
|
||||
# Specifies the tab length.
|
||||
#
|
||||
# tabLength - A {Number} that defines the new tab length.
|
||||
setTabLength: (tabLength) ->
|
||||
@tokenizedBuffer.setTabLength(tabLength)
|
||||
return if tabLength is @tabLength
|
||||
|
||||
@tabLength = tabLength
|
||||
@tokenizedBuffer.setTabLength(@tabLength)
|
||||
@resetDisplayLayer()
|
||||
|
||||
setIgnoreInvisibles: (ignoreInvisibles) ->
|
||||
return if ignoreInvisibles is @ignoreInvisibles
|
||||
|
||||
@@ -117,19 +117,14 @@ class TokenizedBuffer extends Model
|
||||
@grammarUpdateDisposable = @grammar.onDidUpdate => @retokenizeLines()
|
||||
@disposables.add(@grammarUpdateDisposable)
|
||||
|
||||
scopeOptions = {scope: @rootScopeDescriptor}
|
||||
@configSettings =
|
||||
tabLength: @config.get('editor.tabLength', scopeOptions)
|
||||
invisibles: @config.get('editor.invisibles', scopeOptions)
|
||||
showInvisibles: @config.get('editor.showInvisibles', scopeOptions)
|
||||
@configSettings = {tabLength: @config.get('editor.tabLength', {scope: @rootScopeDescriptor})}
|
||||
|
||||
if @configSubscriptions?
|
||||
@configSubscriptions.dispose()
|
||||
@disposables.remove(@configSubscriptions)
|
||||
@configSubscriptions = new CompositeDisposable
|
||||
@configSubscriptions.add @config.onDidChange 'editor.tabLength', scopeOptions, ({newValue}) =>
|
||||
@configSubscriptions.add @config.onDidChange 'editor.tabLength', {scope: @rootScopeDescriptor}, ({newValue}) =>
|
||||
@configSettings.tabLength = newValue
|
||||
@retokenizeLines()
|
||||
@disposables.add(@configSubscriptions)
|
||||
|
||||
@retokenizeLines()
|
||||
@@ -170,7 +165,6 @@ class TokenizedBuffer extends Model
|
||||
return if tabLength is @tabLength
|
||||
|
||||
@tabLength = tabLength
|
||||
@retokenizeLines()
|
||||
|
||||
tokenizeInBackground: ->
|
||||
return if not @visible or @pendingChunk or not @isAlive()
|
||||
@@ -337,18 +331,16 @@ class TokenizedBuffer extends Model
|
||||
openScopes = [@grammar.startIdForScope(@grammar.scopeName)]
|
||||
text = @buffer.lineForRow(row)
|
||||
tags = [text.length]
|
||||
tabLength = @getTabLength()
|
||||
lineEnding = @buffer.lineEndingForRow(row)
|
||||
new TokenizedLine({openScopes, text, tags, tabLength, lineEnding, @tokenIterator})
|
||||
new TokenizedLine({openScopes, text, tags, lineEnding, @tokenIterator})
|
||||
|
||||
buildTokenizedLineForRow: (row, ruleStack, openScopes) ->
|
||||
@buildTokenizedLineForRowWithText(row, @buffer.lineForRow(row), ruleStack, openScopes)
|
||||
|
||||
buildTokenizedLineForRowWithText: (row, text, ruleStack = @stackForRow(row - 1), openScopes = @openScopesForRow(row)) ->
|
||||
lineEnding = @buffer.lineEndingForRow(row)
|
||||
tabLength = @getTabLength()
|
||||
{tags, ruleStack} = @grammar.tokenizeLine(text, ruleStack, row is 0, false)
|
||||
new TokenizedLine({openScopes, text, tags, ruleStack, tabLength, lineEnding, @tokenIterator})
|
||||
new TokenizedLine({openScopes, text, tags, ruleStack, lineEnding, @tokenIterator})
|
||||
|
||||
tokenizedLineForRow: (bufferRow) ->
|
||||
if 0 <= bufferRow < @tokenizedLines.length
|
||||
|
||||
@@ -16,11 +16,7 @@ class TokenizedLine
|
||||
|
||||
return unless properties?
|
||||
|
||||
{@openScopes, @text, @tags, @lineEnding, @ruleStack, @tokenIterator} = properties
|
||||
{@startBufferColumn, @fold, @tabLength, @invisibles} = properties
|
||||
|
||||
@startBufferColumn ?= 0
|
||||
@bufferDelta = @text.length
|
||||
{@openScopes, @text, @tags, @ruleStack, @tokenIterator} = properties
|
||||
|
||||
getTokenIterator: -> @tokenIterator.reset(this, arguments...)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user