Handle a grammar change for @softTabs

This commit is contained in:
Ben Ogle 2015-08-12 17:32:05 -07:00
parent b5d253b9c5
commit 1b727c1862
2 changed files with 25 additions and 0 deletions

View File

@ -3833,6 +3833,23 @@ describe "TextEditor", ->
atom.config.set('editor.tabType', 'auto')
expect(editor.getSoftTabs()).toBe false
describe "when the grammar changes", ->
coffeeEditor = null
beforeEach ->
atom.config.set('editor.tabType', 'hard', scopeSelector: '.source.js')
atom.config.set('editor.tabType', 'soft', scopeSelector: '.source.coffee')
waitsForPromise ->
Promise.all [
atom.packages.activatePackage('language-coffee-script')
atom.project.open('coffee.coffee', autoIndent: false).then (o) -> coffeeEditor = o
]
it "updates based on the value chosen", ->
expect(editor.getSoftTabs()).toBe false
editor.setGrammar(coffeeEditor.getGrammar())
expect(editor.getSoftTabs()).toBe true
describe '.getTabLength()', ->
describe 'when scoped settings are used', ->
coffeeEditor = null

View File

@ -94,6 +94,7 @@ class TextEditor extends Model
marker.setProperties(preserveFolds: true)
@addSelection(marker)
@subscribeToTabTypeConfig()
@subscribeToBuffer()
@subscribeToDisplayBuffer()
@ -178,9 +179,15 @@ class TextEditor extends Model
@subscribe @displayBuffer.onDidAddDecoration (decoration) => @emit 'decoration-added', decoration
@subscribe @displayBuffer.onDidRemoveDecoration (decoration) => @emit 'decoration-removed', decoration
subscribeToTabTypeConfig: ->
@tabTypeSubscription?.dispose()
@tabTypeSubscription = atom.config.observe 'editor.tabType', scope: @getRootScopeDescriptor(), =>
@softTabs = @shouldUseSoftTabs(defaultValue: @softTabs)
destroyed: ->
@unsubscribe() if includeDeprecatedAPIs
@disposables.dispose()
@tabTypeSubscription.dispose()
selection.destroy() for selection in @getSelections()
@buffer.release()
@displayBuffer.destroy()
@ -2895,6 +2902,7 @@ class TextEditor extends Model
handleGrammarChange: ->
@unfoldAll()
@subscribeToTabTypeConfig()
@emitter.emit 'did-change-grammar', @getGrammar()
handleMarkerCreated: (marker) =>