FileFinder only returns up to maxResults

This commit is contained in:
Corey Johnson & Nathan Sobo
2011-12-30 11:36:44 -08:00
parent ad024bc1e6
commit e6053a2d66
3 changed files with 26 additions and 8 deletions

View File

@@ -59,8 +59,13 @@ describe 'FileFinder', ->
expect(finder.find('li:last')).toHaveClass "selected"
describe "findMatches(queryString)", ->
it "returns all urls if queryString is empty", ->
expect(finder.findMatches('')).toEqual urls
it "returns up to finder.maxResults urls if queryString is empty", ->
expect(urls.length).toBeLessThan finder.maxResults
expect(finder.findMatches('').length).toBe urls.length
finder.maxResults = urls.length - 1
expect(finder.findMatches('').length).toBe finder.maxResults
it "returns urls sorted by score of match against the given query", ->
expect(finder.findMatches('ap')).toEqual ["app.coffee", "atom/app.coffee"]

View File

@@ -12,8 +12,11 @@ class FileFinder extends Template
viewProperties:
urls: null
maxResults: null
initialize: ({@urls}) ->
@maxResults = 10
@populateUrlList()
@bindKey 'up', 'moveUp'
@bindKey 'down', 'moveDown'
@@ -43,7 +46,11 @@ class FileFinder extends Template
.addClass('selected')
findMatches: (query) ->
return @urls unless query
scoredUrls = ({url, score: stringScore(url, query)} for url in @urls)
sortedUrls = scoredUrls.sort (a, b) -> a.score > b.score
urlAndScore.url for urlAndScore in sortedUrls when urlAndScore.score > 0
if not query
urls = @urls
else
scoredUrls = ({url, score: stringScore(url, query)} for url in @urls)
scoredUrls.sort (a, b) -> a.score > b.score
urls = (urlAndScore.url for urlAndScore in scoredUrls when urlAndScore.score > 0)
urls.slice 0, @maxResults

View File

@@ -4,12 +4,18 @@
background-color: #444;
color: #eee;
width: 100%;
max-height: 200px;
}
.file-finder input {
width: 100%;
.file-finder ol {
-webkit-box-flex: 1;
overflow: hidden;
}
.file-finder li.selected {
background-color: green;
}
.file-finder input {
width: 100%;
}