Re-tokenize buffer when its grammar is updated

This can happen if a grammar that the grammar includes is added or
removed from the syntax global.
This commit is contained in:
Nathan Sobo
2013-04-21 18:28:58 -06:00
parent 9204836d70
commit 93910201b0
4 changed files with 26 additions and 0 deletions

View File

@@ -34,6 +34,7 @@ class LanguageMode
return if grammar is @grammar
@grammar = grammar
@currentGrammarScore = score ? grammar.getScore(@buffer.getPath(), @buffer.getText())
@subscribe @grammar, 'grammar-updated', => @trigger 'grammar-updated'
@trigger 'grammar-changed', grammar
reloadGrammar: ->

View File

@@ -1,4 +1,6 @@
Token = require 'token'
EventEmitter = require 'event-emitter'
_ = require 'underscore'
###
# Internal #
@@ -14,3 +16,5 @@ class NullGrammar
{ tokens: [new Token(value: line, scopes: ['null-grammar.text.plain'])] }
grammarAddedOrRemoved: -> # no op
_.extend NullGrammar.prototype, EventEmitter

View File

@@ -28,6 +28,7 @@ class TokenizedBuffer
@resetScreenLines()
@buffer.on "changed.tokenized-buffer#{@id}", (e) => @handleBufferChange(e)
@languageMode.on 'grammar-changed', => @resetScreenLines()
@languageMode.on 'grammar-updated', => @resetScreenLines()
resetScreenLines: ->
@screenLines = @buildPlaceholderScreenLinesForRows(0, @buffer.getLastRow())