       levelCodeEditor = workspace.getLevelCodeEditorForTextEditor(textEditor)
       workspace.setActiveLevelCodeEditor(levelCodeEditor)
     else
-      workspace.setActiveLevelCodeEditor(null)
+      workspace.unsetActiveLevelCodeEditor()
 
   handleDidAddTextEditor: ({textEditor}) ->
     @subscribeToTextEditor(textEditor)

    @unsubscribeFromTextEditor(textEditor)

  handleDidChangeGrammar: (textEditor,oldGrammarName,newGrammar) ->
    # do nothing if the grammar was changed due to a level change
    unless newGrammar.name is oldGrammarName
      # update the grammar subscription
      @textEditorSubscrsById[textEditor.id].didChangeGrammarSubscr.dispose()
      @textEditorSubscrsById[textEditor.id].didChangeGrammarSubscr = \
        textEditor.onDidChangeGrammar (grammar) =>
          @handleDidChangeGrammar(textEditor,newGrammar.name,grammar)
      # update Levels workspace based on the new grammar
      language = languageRegistry.getLanguageForGrammar(newGrammar)
      if workspace.isLevelCodeEditor(textEditor)
        levelCodeEditor = workspace.getLevelCodeEditorForTextEditor(textEditor)
        if language?
          # new grammar is a Levels grammar too - update the level code editor
          levelCodeEditor.setLanguage(language)
        else
          # new grammar is not a Levels grammar - destroy the level code editor
          workspace.destroyLevelCodeEditor(levelCodeEditor)
      else
        if language?
          # new grammar is a Levels grammar - a new level code editor is born!
          levelCodeEditor = new LevelCodeEditor(textEditor,language)
          workspace.addLevelCodeEditor(levelCodeEditor)

  ## Language registry subscriptions -------------------------------------------

  subscribeToLanguageRegistry: ->
    languageRegistry.onDidRemoveLanguages (removedLanguages) =>
      @handleDidRemoveLanguages(removedLanguages)

  handleDidRemoveLanguages: (removedLanguages) ->

  ## Consumed services ---------------------------------------------------------


{CompositeDisposable} = require('atom')

languageInstaller     = require('./language-installer').getInstance()
languageRegistry      = require('./language-registry').getInstance()
workspace             = require('./workspace').getInstance()

