Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Support editor.tabType #8356

Merged
merged 12 commits into from
Aug 13, 2015
Prev Previous commit
Next Next commit
Handle a grammar change for @softTabs
  • Loading branch information
benogle committed Aug 13, 2015
commit 1b727c1862add54d016e59a98d5fc5bf164e2436
17 changes: 17 additions & 0 deletions spec/text-editor-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/text-editor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class TextEditor extends Model
marker.setProperties(preserveFolds: true)
@addSelection(marker)

@subscribeToTabTypeConfig()
@subscribeToBuffer()
@subscribeToDisplayBuffer()

Expand Down Expand Up @@ -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()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not super pretty. As I need to either add it to @disposables then remove on a grammar change, or explicitly destroy it in the destroyed method. I chose the latter

@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()
Expand Down Expand Up @@ -2895,6 +2902,7 @@ class TextEditor extends Model

handleGrammarChange: ->
@unfoldAll()
@subscribeToTabTypeConfig()
@emitter.emit 'did-change-grammar', @getGrammar()

handleMarkerCreated: (marker) =>
Expand Down