Add event-palette. Ctrl-enter brings up a list of all events for focused element

No fuzzy finding just yet. This theme of a fuzzy-filterable list is common enough now that I think I want to extract it. We do it in the fuzzy-finder for buffers and files, as well as the autocomplete menu.
This commit is contained in:
Nathan Sobo
2012-10-01 14:08:05 -10:00
parent 7b1fe94e47
commit eaaf6fc9f0
5 changed files with 63 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
RootView = require 'root-view'
EventPalette = require 'event-palette'
$ = require 'jquery'
describe "EventPalette", ->
[rootView, palette] = []
beforeEach ->
rootView = new RootView(require.resolve('fixtures/sample.js'))
rootView.activateExtension(EventPalette)
palette = EventPalette.instance
afterEach ->
rootView.remove()
describe "when shown", ->
ffit "shows a list of all valid events for the previously focused element", ->
rootView.attachToDom().focus()
rootView.trigger 'event-palette:show'
for [event, description] in rootView.getActiveEditor().events()
expect(palette.eventList.find("td:contains(#{event})")).toExist()

View File

@@ -0,0 +1,34 @@
{View, $$} = require 'space-pen'
Editor = require 'editor'
$ = require 'jquery'
module.exports =
class EventPalette extends View
@activate: (rootView) ->
requireStylesheet 'event-palette/event-palette.css'
@instance = new EventPalette(rootView)
rootView.on 'event-palette:show', => @instance.attach()
@content: ->
@div class: 'event-palette', =>
@div class: 'event-list', outlet: 'eventList'
@subview 'miniEditor', new Editor(mini: true)
initialize: (@rootView) ->
attach: ->
@previouslyFocusedElement = $(':focus')
console.log @pre
@populateEventList()
@appendTo(@rootView.vertical)
populateEventList: ->
events = @previouslyFocusedElement.events()
table = $$ ->
@table =>
for [event, description] in events
@tr =>
@td event
@td description if description
@eventList.html(table)

View File

@@ -0,0 +1,5 @@
.event-palette .event-list {
max-height: 300px;
color: white;
overflow-y: auto;
}

View File

@@ -0,0 +1 @@
module.exports = require 'event-palette/event-palette'

View File

@@ -0,0 +1,2 @@
window.keymap.bindKeys 'body'
'ctrl-enter': 'event-palette:show'