Ctrl-enter toggles event palette (hides when showing)

I changed the event name to event-palette:toggle because ctrl-enter
should hide the event palette when it is showing. Previously that
broke, because we would try to re-show the event palette.
This commit is contained in:
Nathan Sobo
2012-10-04 09:44:35 -10:00
parent 66c997f75d
commit a895aa0826
3 changed files with 14 additions and 7 deletions

View File

@@ -11,12 +11,12 @@ describe "EventPalette", ->
rootView.activateExtension(EventPalette)
palette = EventPalette.instance
rootView.attachToDom().focus()
rootView.trigger 'event-palette:show'
rootView.trigger 'event-palette:toggle'
afterEach ->
rootView.remove()
describe "when event-palette:show is triggered on the root view", ->
describe "when event-palette:toggle is triggered on the root view", ->
it "shows a list of all valid events for the previously focused element, then focuses the mini-editor and selects the first event", ->
for [event, description] in rootView.getActiveEditor().events()
expect(palette.list.find(".event:contains(#{event})")).toExist()
@@ -24,6 +24,13 @@ describe "EventPalette", ->
expect(palette.miniEditor.isFocused).toBeTruthy()
expect(palette.find('.event:first')).toHaveClass 'selected'
describe "when event-palette:toggle is triggered on the open event palette", ->
it "focus the root view and detaches the event palette", ->
expect(palette.hasParent()).toBeTruthy()
palette.trigger 'event-palette:toggle'
expect(palette.hasParent()).toBeFalsy()
expect(rootView.getActiveEditor().isFocused).toBeTruthy()
describe "when the event palette is cancelled", ->
it "focuses the root view and detaches the event palette", ->
expect(palette.hasParent()).toBeTruthy()

View File

@@ -8,7 +8,7 @@ class EventPalette extends SelectList
@activate: (rootView) ->
requireStylesheet 'event-palette/event-palette.css'
@instance = new EventPalette(rootView)
rootView.on 'event-palette:show', => @instance.attach()
rootView.on 'event-palette:toggle', => @instance.attach()
@viewClass: ->
"#{super} event-palette"
@@ -16,6 +16,7 @@ class EventPalette extends SelectList
filterKey: 0 # filter on the event name for now
initialize: (@rootView) ->
@on 'event-palette:toggle', => @cancel()
super
attach: ->

View File

@@ -1,6 +1,5 @@
window.keymap.bindKeys 'body'
'ctrl-enter': 'event-palette:show'
window.keymap.bindKeys 'body, .event-palette .editor'
'ctrl-enter': 'event-palette:toggle'
window.keymap.bindKeys '.event-palette .editor'
'enter': 'event-palette:select'
'escape': 'event-palette:cancel'
'ctrl-enter': 'event-palette:toggle'