   # Enabled-disabled-cycle
 
   checkGrammar: =>
-    @deactivate()
-    ext = extname(@editor.getTitle()).replace(/^\./, '')
-    return unless (@language = @languages.getDefinition ext)?
-    @activate()
+    language = @languages.getDefinition extname(@editor.getTitle()).replace(/^\./, '')
+    if @language isnt language
+      @deactivate()
+      @activate language
 
-  activate: ->
-    return if @isActive
+  activate: (@language) ->
+    return unless @language?
 
     # Start listening
     @editorView.on 'html-img:fill', @onFill

  constructor: (@editorView, @languages) ->
    super()
    @languages = Languages.getInstance()
    @isActive = false
    @editor = @editorView.editor
    @editor.on 'grammar-changed', @checkGrammar
    @editor.on 'destroyed', @onDestroyed

    @editorView.on 'html-img:fill-height-half', @onFillHeightHalf

  deactivate: ->
    return unless @language?

    # Stop listening
    @editorView.off 'html-img:fill', @onFill
