Show root view events when no element has focus

Closes #327
This commit is contained in:
Kevin Sawicki
2013-03-27 14:26:53 -04:00
parent 4c9ebc940c
commit 7f8adf247e
2 changed files with 24 additions and 3 deletions

View File

@@ -29,10 +29,14 @@ class CommandPaletteView extends SelectList
attach: ->
super
@keyBindings = _.losslessInvert(keymap.bindingsForElement(@previouslyFocusedElement))
if @previouslyFocusedElement[0]
@eventElement = @previouslyFocusedElement
else
@eventElement = rootView
@keyBindings = _.losslessInvert(keymap.bindingsForElement(@eventElement))
events = []
for eventName, eventDescription of _.extend($(window).events(), @previouslyFocusedElement.events())
for eventName, eventDescription of _.extend($(window).events(), @eventElement.events())
events.push({eventName, eventDescription}) if eventDescription
events = _.sortBy events, (e) -> e.eventDescription
@@ -52,4 +56,4 @@ class CommandPaletteView extends SelectList
confirmed: ({eventName}) ->
@cancel()
@previouslyFocusedElement.trigger(eventName)
@eventElement.trigger(eventName)

View File

@@ -81,3 +81,20 @@ describe "CommandPalette", ->
expect(activeEditor.isFocused).toBeTruthy()
expect(eventHandler).toHaveBeenCalled()
expect(palette.hasParent()).toBeFalsy()
describe "when no element has focus", ->
it "uses the root view as the element to display and trigger events for", ->
rootView.trigger 'command-palette:toggle'
$(':focus').blur()
rootView.trigger 'command-palette:toggle'
keyBindings = _.losslessInvert(keymap.bindingsForElement(rootView.getActiveView()))
for eventName, description of rootView.events()
eventLi = palette.list.children("[data-event-name='#{eventName}']")
if description
expect(eventLi).toExist()
expect(eventLi.find('.label')).toHaveText(description)
expect(eventLi.find('.label').attr('title')).toBe(eventName)
for binding in keyBindings[eventName] ? []
expect(eventLi.find(".key-binding:contains(#{binding})")).toExist()
else
expect(eventLi).not.toExist()