diff --git a/package.json b/package.json index 2b95a2b34..ec30ddedb 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "delegato": "^1", "emissary": "^1.3.1", "event-kit": "0.7.1", - "first-mate": "^2.0.6", + "first-mate": "^2.1.0", "fs-plus": "^2.2.6", "fstream": "0.1.24", "fuzzaldrin": "^2.1", diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 46d43ed7d..4bad73ee7 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -137,7 +137,7 @@ afterEach -> jasmine.unspy(atom, 'saveSync') ensureNoPathSubscriptions() - atom.syntax.off() + atom.syntax.clearObservers() waits(0) # yield to ui thread to make screen update more frequently ensureNoPathSubscriptions = -> diff --git a/src/tokenized-buffer.coffee b/src/tokenized-buffer.coffee index db64f597a..8872b6e01 100644 --- a/src/tokenized-buffer.coffee +++ b/src/tokenized-buffer.coffee @@ -27,12 +27,8 @@ class TokenizedBuffer extends Model @tabLength ?= atom.config.getPositiveInt('editor.tabLength', 2) - @subscribe atom.syntax, 'grammar-added grammar-updated', (grammar) => - if grammar.injectionSelector? - @retokenizeLines() if @hasTokenForSelector(grammar.injectionSelector) - else - newScore = grammar.getScore(@buffer.getPath(), @buffer.getText()) - @setGrammar(grammar, newScore) if newScore > @currentGrammarScore + @subscribe atom.syntax.onDidAddGrammar(@grammarAddedOrUpdated) + @subscribe atom.syntax.onDidUpdateGrammar(@grammarAddedOrUpdated) @subscribe @buffer.onDidChange (e) => @handleBufferChange(e) @subscribe @buffer.onDidChangePath (@bufferPath) => @reloadGrammar() @@ -75,12 +71,19 @@ class TokenizedBuffer extends Model EmitterMixin::on.apply(this, arguments) + grammarAddedOrUpdated: (grammar) => + if grammar.injectionSelector? + @retokenizeLines() if @hasTokenForSelector(grammar.injectionSelector) + else + newScore = grammar.getScore(@buffer.getPath(), @buffer.getText()) + @setGrammar(grammar, newScore) if newScore > @currentGrammarScore + setGrammar: (grammar, score) -> return if grammar is @grammar @unsubscribe(@grammar) if @grammar @grammar = grammar @currentGrammarScore = score ? grammar.getScore(@buffer.getPath(), @buffer.getText()) - @subscribe @grammar, 'grammar-updated', => @retokenizeLines() + @subscribe @grammar.onDidUpdate => @retokenizeLines() @retokenizeLines() @emit 'grammar-changed', grammar @emitter.emit 'did-change-grammar', grammar