     selection.cursor.setBufferPosition(cursorPosition)
     word
 
-  observeTextEditors: ->
-    QuickHighlightView ?= require './quick-highlight-view'
-    KeywordManager ?= require './keyword-manager'
-    StatusBarManager ?= require './status-bar-manager'
+  initQuickHighlightIfNeeded: ->
+    return if @editorSubscription?
+
+    QuickHighlightView = require './quick-highlight-view'
+    KeywordManager = require './keyword-manager'
+    StatusBarManager = require './status-bar-manager'
 
     @keywordManager = new KeywordManager
     @statusBarManager = new StatusBarManager

      view = new QuickHighlightView(editor, options)
      @viewByEditor.set(editor, view)

  toggle: (editor, keyword) ->
    keyword ?= editor.getSelectedText() or @getCursorWord(editor)
    @editorSubscription ?= @observeTextEditors()
    @keywordManager.toggle(keyword)

  onDidChangeHighlight: (fn) ->

    @subscriptions = new CompositeDisposable
    @emitter = new Emitter
    @viewByEditor = new Map
    @subscriptions.add atom.commands.add 'atom-text-editor:not([mini])',
      'quick-highlight:toggle': => @toggle()
      'quick-highlight:clear': => @keywordManager?.clear()

    @subscriptions.add atom.config.observe 'quick-highlight.highlightSelection', (value) =>
      if value
        @initQuickHighlightIfNeeded()

  deactivate: ->
    @keywordManager?.destroy()
    @keywordManager = null

    @viewByEditor.forEach (view) -> view.destroy()
    @viewByEditor.clear()
    @viewByEditor = null

    @subscriptions.dispose()
    @subscriptions = null

    @editorSubscription?.dispose()
    @editorSubscription = null

    @statusBarManager?.detach()
    @statusBarManager = null

  getCursorWord: (editor) ->
    selection = editor.getLastSelection()
