diff --git a/lib/project-find-view.coffee b/lib/project-find-view.coffee index 63997198..0eec7e77 100644 --- a/lib/project-find-view.coffee +++ b/lib/project-find-view.coffee @@ -47,6 +47,7 @@ class ProjectFindView extends View @findHistory = new History(@findEditor, findHistory) @replaceHistory = new History(@replaceEditor, replaceHistory) @pathsHistory = new History(@pathsEditor, pathsHistory) + @onlyRunIfChanged = true @regexOptionButton.addClass('selected') if @model.useRegex @caseOptionButton.addClass('selected') if @model.caseSensitive @@ -91,6 +92,8 @@ class ProjectFindView extends View @subscribe @model, 'replacement-state-cleared', (results) => @generateResultsMessage(results) @subscribe @model, 'finished-searching', (results) => @generateResultsMessage(results) + @subscribe $(window), 'focus', => @onlyRunIfChanged = false + atom.workspaceView.command 'find-and-replace:use-selection-as-find-pattern', @setSelectionAsFindPattern @handleEventsForReplace() @@ -158,7 +161,9 @@ class ProjectFindView extends View @replaceHistory.store() @pathsHistory.store() - @search(onlyRunIfChanged: true) + searchPromise = @search({@onlyRunIfChanged}) + @onlyRunIfChanged = true + searchPromise search: ({onlyRunIfActive, onlyRunIfChanged}={}) -> return Q() if onlyRunIfActive and not @model.active diff --git a/spec/project-find-view-spec.coffee b/spec/project-find-view-spec.coffee index b2cf42e2..27266b26 100644 --- a/spec/project-find-view-spec.coffee +++ b/spec/project-find-view-spec.coffee @@ -375,6 +375,40 @@ describe 'ProjectFindView', -> expect(atom.project.scan).not.toHaveBeenCalled() expect(projectFindView.model.clear).toHaveBeenCalled() + it "reruns the search when confirmed again after focusing the window", -> + projectFindView.findEditor.setText('thisdoesnotmatch') + projectFindView.trigger 'core:confirm' + + waitsForPromise -> + searchPromise + + runs -> + spyOn(atom.project, 'scan') + projectFindView.trigger 'core:confirm' + + waitsForPromise -> + searchPromise + + runs -> + expect(atom.project.scan).not.toHaveBeenCalled() + atom.project.scan.reset() + $(window).triggerHandler 'focus' + projectFindView.trigger 'core:confirm' + + waitsForPromise -> + searchPromise + + runs -> + expect(atom.project.scan).toHaveBeenCalled() + atom.project.scan.reset() + projectFindView.trigger 'core:confirm' + + waitsForPromise -> + searchPromise + + runs -> + expect(atom.project.scan).not.toHaveBeenCalled() + describe "when results exist", -> beforeEach -> projectFindView.findEditor.setText('items')