Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Allow rerunning the search after window focus
Browse files Browse the repository at this point in the history
The files being searched may have changed due to modifications
done outside of Atom.

Closes #169
  • Loading branch information
kevinsawicki committed Apr 9, 2014
1 parent ed9f866 commit 27c9b51
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/project-find-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions spec/project-find-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 27c9b51

Please sign in to comment.