 
   onActiveItemChanged: =>
     return unless window.rootView
-    editor = rootView.getActiveView()
+    editor = @currentEditor()
     @trigger('active-editor-changed', editor: editor)
 
   onCursorMoved: =>

  replaceNext: =>
    @search()
    replacement = @replaceEditor.getText()
    rootView.getActiveView().trigger('find-and-replace:replace-next', {replacement})

  replaceAll: =>
    @search()
    replacement = @replaceEditor.getText()
    rootView.getActiveView().trigger('find-and-replace:replace-all', {replacement})

  findPrevious: =>
    @cursorMoveOriginatedHere = true # See HACK above.
    rootView.getActiveView().trigger('find-and-replace:find-previous')

  findNext: =>
    @cursorMoveOriginatedHere = true # See HACK above.
    rootView.getActiveView().trigger('find-and-replace:find-next')

  toggleRegexOption: => @toggleOption('regex')


    @active = false
    view.deactivate() for view in @searchResultsViews

  currentEditor: ->
    rootView.getActiveView()


