mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
FileFinder only returns up to maxResults
This commit is contained in:
@@ -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"]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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%;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user