Project.scan scans buffer if the file is modified

Closes #487
This commit is contained in:
probablycorey 2013-10-24 15:32:32 -07:00
parent c424f7bafa
commit 1f30231d5c
2 changed files with 25 additions and 1 deletions

View File

@ -429,3 +429,16 @@ describe "Project", ->
runs ->
expect(resultHandler).not.toHaveBeenCalled()
it "scans buffer contents if the buffer is modified", ->
editSession = project.openSync("a")
editSession.setText("Elephant")
results = []
waitsForPromise ->
project.scan /a|Elephant/, (result) -> results.push result
runs ->
expect(results).toHaveLength 3
resultForA = _.find results, ({filePath}) -> path.basename(filePath) == 'a'
expect(resultForA.matches).toHaveLength 1
expect(resultForA.matches[0].matchText).toBe 'Elephant'

View File

@ -218,6 +218,11 @@ class Project
getBuffers: ->
new Array(@buffers...)
isPathModified: (filePath) ->
absoluteFilePath = @resolve(filePath)
existingBuffer = _.find @buffers, (buffer) -> buffer.getPath() == absoluteFilePath
existingBuffer?.isModified()
# Private: Only to be used in specs
bufferForPathSync: (filePath, text) ->
absoluteFilePath = @resolve(filePath)
@ -315,12 +320,18 @@ class Project
deferred.resolve()
task.on 'scan:result-found', (result) =>
iterator(result)
iterator(result) unless @isPathModified(result.filePath)
if _.isFunction(options.onPathsSearched)
task.on 'scan:paths-searched', (numberOfPathsSearched) ->
options.onPathsSearched(numberOfPathsSearched)
for buffer in @buffers when buffer.isModified()
filePath = buffer.getPath()
matches = []
buffer.scan regex, (match) -> matches.push match
iterator {filePath, matches} if matches.length > 0
deferred.promise
# Private: