mirror of
https://github.com/atom/atom.git
synced 2026-01-25 23:08:18 -05:00
Select list wraps around when handling move-up / move-down events
This commit is contained in:
@@ -2,7 +2,7 @@ SelectList = require 'select-list'
|
||||
{$$} = require 'space-pen'
|
||||
$ = require 'jquery'
|
||||
|
||||
describe "SelectList", ->
|
||||
fdescribe "SelectList", ->
|
||||
[selectList, array, list, miniEditor] = []
|
||||
|
||||
beforeEach ->
|
||||
@@ -37,12 +37,18 @@ describe "SelectList", ->
|
||||
expect(list.find('li:contains(Delta)')).toExist()
|
||||
|
||||
describe "when move-up / move-down are triggered on the miniEditor", ->
|
||||
it "selects the previous / next item in the list, if there is one", ->
|
||||
it "selects the previous / next item in the list, or wraps around to the other side", ->
|
||||
expect(list.find('li:first')).toHaveClass 'selected'
|
||||
|
||||
miniEditor.trigger 'move-up'
|
||||
|
||||
expect(list.find('li:first')).not.toHaveClass 'selected'
|
||||
expect(list.find('li:last')).toHaveClass 'selected'
|
||||
|
||||
miniEditor.trigger 'move-down'
|
||||
|
||||
expect(list.find('li:first')).toHaveClass 'selected'
|
||||
expect(list.find('li:last')).not.toHaveClass 'selected'
|
||||
|
||||
miniEditor.trigger 'move-down'
|
||||
|
||||
@@ -59,6 +65,7 @@ describe "SelectList", ->
|
||||
expect(list.find('li:eq(2)')).not.toHaveClass 'selected'
|
||||
expect(list.find('li:eq(1)')).toHaveClass 'selected'
|
||||
|
||||
|
||||
it "scrolls to keep the selected item in view", ->
|
||||
selectList.attachToDom()
|
||||
itemHeight = list.find('li').outerHeight()
|
||||
|
||||
@@ -42,16 +42,19 @@ class SelectList extends View
|
||||
@list.append(item)
|
||||
|
||||
selectPreviousItem: ->
|
||||
@selectItem(@getSelectedItem().prev())
|
||||
item = @getSelectedItem().prev()
|
||||
item = @list.find('li:last') unless item.length
|
||||
@selectItem(item)
|
||||
|
||||
selectNextItem: ->
|
||||
@selectItem(@getSelectedItem().next())
|
||||
item = @getSelectedItem().next()
|
||||
item = @list.find('li:first') unless item.length
|
||||
@selectItem(item)
|
||||
|
||||
selectItem: (item) ->
|
||||
if item.length
|
||||
@list.find('.selected').removeClass('selected')
|
||||
item.addClass 'selected'
|
||||
@scrollToItem(item)
|
||||
@list.find('.selected').removeClass('selected')
|
||||
item.addClass 'selected'
|
||||
@scrollToItem(item)
|
||||
|
||||
scrollToItem: (item) ->
|
||||
scrollTop = @list.scrollTop()
|
||||
|
||||
Reference in New Issue
Block a user