From 1e9b40a6ea9ac4eaddd7efb30c46b429d7d2d37c Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 3 Oct 2012 21:04:44 -1000 Subject: [PATCH] Select the first list item after changing the list filter --- spec/extensions/select-list-spec.coffee | 3 ++- src/app/select-list.coffee | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/extensions/select-list-spec.coffee b/spec/extensions/select-list-spec.coffee index b88746a6c..f320efaff 100644 --- a/spec/extensions/select-list-spec.coffee +++ b/spec/extensions/select-list-spec.coffee @@ -30,11 +30,12 @@ fdescribe "SelectList", -> expect(list.find('li:eq(0)')).toHaveClass 'A' describe "when the text of the mini editor changes", -> - it "filters the elements in the list based on the scoreElement function", -> + it "filters the elements in the list based on the scoreElement function and selects the first item", -> miniEditor.insertText('la') expect(list.find('li').length).toBe 2 expect(list.find('li:contains(Alpha)')).toExist() expect(list.find('li:contains(Delta)')).toExist() + expect(list.find('li:first')).toHaveClass 'selected' describe "when move-up / move-down are triggered on the miniEditor", -> it "selects the previous / next item in the list, or wraps around to the other side", -> diff --git a/src/app/select-list.coffee b/src/app/select-list.coffee index 91a087147..b7f2ca277 100644 --- a/src/app/select-list.coffee +++ b/src/app/select-list.coffee @@ -52,6 +52,8 @@ class SelectList extends View item.data('select-list-element', element) @list.append(item) + @selectItem(@list.find('li:first')) + selectPreviousItem: -> item = @getSelectedItem().prev() item = @list.find('li:last') unless item.length