Properly append and count matches

This commit is contained in:
Garen Torikian
2013-03-27 16:18:25 -07:00
parent 416f654d2c
commit 6a08827830
4 changed files with 23 additions and 7 deletions

View File

@@ -177,7 +177,6 @@ class Project
for [column, length] in matchPositions
range = new Range([row, column], [row, column + length])
match = lineText.substr(column, length)
console.log(path)
iterator({path, range, match})
deferred = $.Deferred()

View File

@@ -119,6 +119,7 @@ class CommandPanelView extends View
@previewHeader.show()
@searchLoadingMessage.show()
@errorMessages.empty()
project.previewList = @previewList
try
@commandInterpreter.eval(command, rootView.getActivePaneItem()).done ({operationsToPreview, errorMessages}) =>
@@ -133,7 +134,7 @@ class CommandPanelView extends View
@li errorMessage for errorMessage in errorMessages
else if operationsToPreview?.length
@previewList.focus()
@previewCount.text("#{_.pluralize(operationsToPreview.length, 'match', 'matches')} in #{_.pluralize(@previewList.getPathCount(), 'file')}").show()
@previewCount.text("#{_.pluralize(operationsToPreview.length, 'match', 'matches')} in #{_.pluralize(@previewList.getPathCount(operationsToPreview), 'file')}").show()
else
@detach()
catch error

View File

@@ -14,11 +14,13 @@ class SelectAllMatchesInProject extends Command
deferred = $.Deferred()
operations = []
promise = project.scan @regex, ({path, range}) ->
operations.push(new Operation(
op = new Operation(
project: project
path: path
bufferRange: range
))
)
project.previewList.populateSingle(op)
operations.push(op)
promise.done -> deferred.resolve(operations)
deferred.promise()

View File

@@ -39,7 +39,6 @@ class PreviewList extends ScrollView
hasOperations: -> @operations?
populate: (operations) ->
debugger;
@destroyOperations() if @operations
@operations = operations
@lastRenderedOperationIndex = 0
@@ -51,6 +50,14 @@ class PreviewList extends ScrollView
@find('.operation:first').addClass('selected')
populateSingle: (operation) ->
@viewsForPath = {}
@show()
@renderOperation(operation)
@find('.operation:first').addClass('selected')
renderOperations: ({renderAll}={}) ->
renderAll ?= false
startingScrollHeight = @prop('scrollHeight')
@@ -60,6 +67,13 @@ class PreviewList extends ScrollView
@lastRenderedOperationIndex++
break if not renderAll and @prop('scrollHeight') >= startingScrollHeight + @pixelOverdraw and @prop('scrollHeight') > @height() + @pixelOverdraw
renderOperation: (operation, {renderAll}={}) ->
renderAll ?= false
startingScrollHeight = @prop('scrollHeight')
pathView = @pathViewForPath(operation.getPath())
pathView.addOperation(operation)
pathViewForPath: (path) ->
pathView = @viewsForPath[path]
if not pathView
@@ -97,8 +111,8 @@ class PreviewList extends ScrollView
previousView.addClass('selected')
previousView.scrollTo()
getPathCount: ->
_.keys(_.groupBy(@operations, (operation) -> operation.getPath())).length
getPathCount: (operations=@operations)->
_.keys(_.groupBy(operations, (operation) -> operation.getPath())).length
getOperations: ->
new Array(@operations...)