From 22aeda6f1c41efd8d436126519676f32a8aabb4c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 25 Jan 2013 17:31:38 -0800 Subject: [PATCH] Add move-to-top/bottom support to select list --- spec/app/select-list-spec.coffee | 13 +++++++++++++ src/app/select-list.coffee | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/spec/app/select-list-spec.coffee b/spec/app/select-list-spec.coffee index e4e4d32cc..88b7990a8 100644 --- a/spec/app/select-list-spec.coffee +++ b/spec/app/select-list-spec.coffee @@ -164,3 +164,16 @@ describe "SelectList", -> miniEditor.trigger 'focusout' expect(selectList.cancelled).toHaveBeenCalled() expect(selectList.detach).toHaveBeenCalled() + + describe "the core:move-to-top event", -> + it "scrolls to the bottom and selects the last element", -> + selectList.trigger 'core:move-down' + expect(list.find('li:eq(1)')).toHaveClass 'selected' + selectList.trigger 'core:move-to-top' + expect(list.find('li:first')).toHaveClass 'selected' + + describe "the core:move-to-bottom event", -> + it "scrolls to the bottom and selects the last element", -> + expect(list.find('li:first')).toHaveClass 'selected' + selectList.trigger 'core:move-to-bottom' + expect(list.find('li:last')).toHaveClass 'selected' diff --git a/src/app/select-list.coffee b/src/app/select-list.coffee index 5bdb3258d..0b4cd9a87 100644 --- a/src/app/select-list.coffee +++ b/src/app/select-list.coffee @@ -26,6 +26,12 @@ class SelectList extends View @miniEditor.on 'focusout', => @cancel() unless @cancelling @on 'core:move-up', => @selectPreviousItem() @on 'core:move-down', => @selectNextItem() + @on 'core:move-to-top', => + @selectItem(@list.find('li:first')) + @list.scrollToTop() + @on 'core:move-to-bottom', => + @selectItem(@list.find('li:last')) + @list.scrollToBottom() @on 'core:confirm', => @confirmSelection() @on 'core:cancel', => @cancel()