From 2991048c1ee0bec61db228cc2b2e11b66ab972c8 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 3 Oct 2012 20:44:12 -1000 Subject: [PATCH] SelectList allows list items to be clicked --- spec/extensions/fuzzy-finder-spec.coffee | 17 ----------------- spec/extensions/select-list-spec.coffee | 12 +++++++++++- src/app/select-list.coffee | 12 +++++++++++- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/spec/extensions/fuzzy-finder-spec.coffee b/spec/extensions/fuzzy-finder-spec.coffee index 6dc075c6f..87f2af328 100644 --- a/spec/extensions/fuzzy-finder-spec.coffee +++ b/spec/extensions/fuzzy-finder-spec.coffee @@ -175,20 +175,3 @@ describe 'FuzzyFinder', -> expect(finder.hasParent()).toBeFalsy() expect(activeEditor.isFocused).toBeTruthy() expect(finder.miniEditor.isFocused).toBeFalsy() - - describe "selecting a path with the mouse", -> - it "opens the clicked path in the active editor and focuses it", -> - rootView.attachToDom() - rootView.trigger 'fuzzy-finder:toggle-file-finder' - - selectedLi = finder.find('li:eq(1)') - - expectedPath = rootView.project.resolve(selectedLi.text()) - expect(rootView.getActiveEditor().getPath()).not.toBe expectedPath - expect(rootView.getActiveEditor().isFocused).toBeFalsy() - - selectedLi.mousedown() - - expect(rootView.getActiveEditor().getPath()).toBe expectedPath - expect(rootView.getActiveEditor().isFocused).toBeTruthy() - diff --git a/spec/extensions/select-list-spec.coffee b/spec/extensions/select-list-spec.coffee index 490c44114..b88746a6c 100644 --- a/spec/extensions/select-list-spec.coffee +++ b/spec/extensions/select-list-spec.coffee @@ -96,6 +96,16 @@ fdescribe "SelectList", -> miniEditor.trigger 'core:confirm' expect(selectList.confirmed).not.toHaveBeenCalled() + describe "when a list item is clicked", -> + it "selects the item on mousedown and confirms it on mouseup", -> + item = list.find('li:eq(1)') + + item.mousedown() + expect(item).toHaveClass 'selected' + item.mouseup() + + expect(selectList.confirmed).toHaveBeenCalledWith(array[1]) + describe "the core:cancel event", -> it "triggers the cancelled hook and detaches the select list", -> spyOn(selectList, 'detach') @@ -103,7 +113,7 @@ fdescribe "SelectList", -> expect(selectList.cancelled).toHaveBeenCalled() expect(selectList.detach).toHaveBeenCalled() - describe "when the fuzzy finder loses focus", -> + describe "when the mini editor loses focus", -> it "triggers the cancelled hook and detaches the select list", -> spyOn(selectList, 'detach') miniEditor.trigger 'focusout' diff --git a/src/app/select-list.coffee b/src/app/select-list.coffee index d2b6e64e4..91a087147 100644 --- a/src/app/select-list.coffee +++ b/src/app/select-list.coffee @@ -18,6 +18,7 @@ class SelectList extends View initialize: -> requireStylesheet 'select-list.css' + @miniEditor.getBuffer().on 'change', => @populateList() @miniEditor.on 'focusout', => @cancel() unless @cancelling @on 'move-up', => @selectPreviousItem() @@ -25,6 +26,14 @@ class SelectList extends View @on 'core:confirm', => @confirmSelection() @on 'core:cancel', => @cancel() + @list.on 'mousedown', 'li', (e) => + @selectItem($(e.target).closest('li')) + e.preventDefault() + + @list.on 'mouseup', 'li', (e) => + @confirmSelection() if $(e.target).closest('li').hasClass('selected') + e.preventDefault() + setArray: (@array) -> @populateList() @selectItem(@list.find('li:first')) @@ -54,6 +63,7 @@ class SelectList extends View @selectItem(item) selectItem: (item) -> + return unless item.length @list.find('.selected').removeClass('selected') item.addClass 'selected' @scrollToItem(item) @@ -77,7 +87,7 @@ class SelectList extends View cancel: -> @cancelling = true - @cancelled() @detach() + @cancelled() @cancelling = false