Wrap around fuzzy finder when at top or bottom

This commit is contained in:
Kevin Sawicki
2012-10-02 10:39:35 -07:00
parent f51c5dffed
commit 189e3be5ae
2 changed files with 19 additions and 16 deletions

View File

@@ -223,16 +223,15 @@ describe 'FuzzyFinder', ->
expect(finder.find('li:eq(1)')).toHaveClass "selected"
expect(finder.find('li:eq(2)')).not.toHaveClass "selected"
it "does not fall off the end or begining of the list", ->
it "wraps around when at the end or begining of the list", ->
expect(finder.find('li:first')).toHaveClass "selected"
finder.miniEditor.trigger keydownEvent('up')
expect(finder.find('li:first')).toHaveClass "selected"
for i in [1..finder.pathList.children().length+2]
finder.miniEditor.trigger keydownEvent('down')
expect(finder.find('li:last')).toHaveClass "selected"
finder.miniEditor.trigger keydownEvent('down')
expect(finder.find('li:first')).toHaveClass "selected"
describe "when the fuzzy finder loses focus", ->
it "detaches itself", ->
rootView.attachToDom()

View File

@@ -93,18 +93,22 @@ class FuzzyFinder extends View
false
moveUp: ->
@findSelectedLi()
.filter(':not(:first-child)')
.removeClass('selected')
.prev()
.addClass('selected')
selected = @findSelectedLi().removeClass('selected')
if selected.filter(':not(:first-child)').length is 0
selected = @pathList.children('li:last')
else
selected = selected.prev()
selected.addClass('selected')
moveDown: ->
@findSelectedLi()
.filter(':not(:last-child)')
.removeClass('selected')
.next()
.addClass('selected')
selected = @findSelectedLi().removeClass('selected')
if selected.filter(':not(:last-child)').length is 0
selected = @pathList.children('li:first')
else
selected = selected.next()
selected.addClass('selected')
findMatches: (query) ->
fuzzyFilter(@paths, query, maxResults: @maxResults)