mirror of
https://github.com/atom/atom.git
synced 2026-01-25 23:08:18 -05:00
SelectList allows list items to be clicked
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user