     promise = atom.project.scan @regex, {paths, onPathsSearched}, (result) =>
       @setResult(result.filePath, result.matches)
 
-    promise.done => @emit('finished-searching')
-
     @emit('search', promise)
-
-    promise
+    promise.then => @emit('finished-searching')
 
   replace: (pattern, replacementText, paths) ->
     regex = @getRegex(pattern)

        replacements += result.replacements
      @emit('path-replaced', result)

    promise.done =>
      @clear()
      @emit('finished-replacing', {pathsReplaced, replacements})

    @emit('replace', promise)

    promise

  toggleUseRegex: ->
    @useRegex = not @useRegex

    @pattern = ''
    @emit('cleared')

  search: (pattern, paths, onlyRunIfChanged = false) ->
    return Q() if onlyRunIfChanged and pattern? and paths? and pattern == @pattern and _.isEqual(paths, @searchedPaths)

    @clear()
    @active = true
