mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
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:
21
spec/extensions/event-palette-spec.coffee
Normal file
21
spec/extensions/event-palette-spec.coffee
Normal 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()
|
||||
34
src/extensions/event-palette/event-palette.coffee
Normal file
34
src/extensions/event-palette/event-palette.coffee
Normal 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)
|
||||
5
src/extensions/event-palette/event-palette.css
Normal file
5
src/extensions/event-palette/event-palette.css
Normal file
@@ -0,0 +1,5 @@
|
||||
.event-palette .event-list {
|
||||
max-height: 300px;
|
||||
color: white;
|
||||
overflow-y: auto;
|
||||
}
|
||||
1
src/extensions/event-palette/index.coffee
Normal file
1
src/extensions/event-palette/index.coffee
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require 'event-palette/event-palette'
|
||||
2
src/extensions/event-palette/keymap.coffee
Normal file
2
src/extensions/event-palette/keymap.coffee
Normal file
@@ -0,0 +1,2 @@
|
||||
window.keymap.bindKeys 'body'
|
||||
'ctrl-enter': 'event-palette:show'
|
||||
Reference in New Issue
Block a user