Handle changes to the tabLength setting

This commit is contained in:
Ben Ogle 2014-10-03 16:22:16 -07:00
parent 339cb02269
commit 8cd217e50a
3 changed files with 25 additions and 6 deletions

View File

@ -3057,6 +3057,24 @@ describe "TextEditor", ->
coffeeEditor.setCursorBufferPosition [0, 10]
expect(coffeeEditor.getTabLength(coffeeEditor.scopesAtCursor())).toBe 4
it 'will retokenize when the tab length is updated', ->
expect(editor.getTabLength()).toBe 2
expect(editor.tokenizedLineForScreenRow(5).tokens[0].firstNonWhitespaceIndex).toBe 2
atom.config.set '.source.js', 'editor.tabLength', 6
expect(editor.getTabLength()).toBe 6
expect(editor.tokenizedLineForScreenRow(5).tokens[0].firstNonWhitespaceIndex).toBe 6
it 'will update the tab length when the grammar changes', ->
atom.config.set '.source.coffee', 'editor.tabLength', 6
expect(editor.getTabLength()).toBe 2
expect(editor.tokenizedLineForScreenRow(5).tokens[0].firstNonWhitespaceIndex).toBe 2
editor.setGrammar(coffeeEditor.getGrammar())
expect(editor.getTabLength()).toBe 6
expect(editor.tokenizedLineForScreenRow(5).tokens[0].firstNonWhitespaceIndex).toBe 6
describe ".indentLevelForLine(line)", ->
it "returns the indent level when the line has only leading whitespace", ->
expect(editor.indentLevelForLine(" hello")).toBe(2)

View File

@ -485,10 +485,9 @@ class TextEditor extends Model
# Create an {TextEditor} with its initial state based on this object
copy: ->
tabLength = @getTabLength()
displayBuffer = @displayBuffer.copy()
softTabs = @getSoftTabs()
newEditor = new TextEditor({@buffer, displayBuffer, tabLength, softTabs, suppressCursorCreation: true, registerEditor: true})
newEditor = new TextEditor({@buffer, displayBuffer, @tabLength, softTabs, suppressCursorCreation: true, registerEditor: true})
for marker in @findMarkers(editorId: @id)
marker.copy(editorId: newEditor.id, preserveFolds: true)
newEditor

View File

@ -31,10 +31,6 @@ class TokenizedBuffer extends Model
@subscribe @buffer.onDidChange (e) => @handleBufferChange(e)
@subscribe @buffer.onDidChangePath (@bufferPath) => @reloadGrammar()
# TODO: FIXME: make this work for scoped properties
@subscribe @$tabLength.changes, (tabLength) => @retokenizeLines()
@subscribe atom.config.onDidChange 'editor.tabLength', ({newValue}) => @setTabLength(newValue)
@reloadGrammar()
serializeParams: ->
@ -83,6 +79,12 @@ class TokenizedBuffer extends Model
@currentGrammarScore = score ? grammar.getScore(@buffer.getPath(), @buffer.getText())
@subscribe @grammar.onDidUpdate => @retokenizeLines()
@retokenizeLines()
@grammarTabLengthSubscription?.dispose()
@grammarTabLengthSubscription = atom.config.onDidChange @grammarScopeDescriptor, 'editor.tabLength', =>
@retokenizeLines()
@subscribe @grammarTabLengthSubscription
@emit 'grammar-changed', grammar
@emitter.emit 'did-change-grammar', grammar