mirror of
https://github.com/atom/atom.git
synced 2026-01-25 06:48:28 -05:00
Display keybindings in EventPalette. Style a bit.
This commit is contained in:
@@ -17,15 +17,20 @@ describe "EventPalette", ->
|
||||
rootView.remove()
|
||||
|
||||
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", ->
|
||||
it "shows a list of all valid event descriptions, names, and keybindings for the previously focused element", ->
|
||||
keyBindings = _.losslessInvert(keymap.bindingsForElement(rootView.getActiveEditor()))
|
||||
for eventName, description of rootView.getActiveEditor().events()
|
||||
eventLi = palette.list.children("[data-event-name='#{eventName}']")
|
||||
if description
|
||||
expect(eventLi).toExist()
|
||||
expect(eventLi.children('.event-name')).toHaveText(eventName)
|
||||
expect(eventLi.children('.event-description')).toHaveText(description)
|
||||
for binding in keyBindings[eventName] ? []
|
||||
expect(eventLi.children(".key-binding:contains(#{binding})")).toExist()
|
||||
else
|
||||
expect(eventLi).not.toExist()
|
||||
|
||||
it "focuses the mini-editor and selects the first event", ->
|
||||
expect(palette.miniEditor.isFocused).toBeTruthy()
|
||||
expect(palette.find('.event:first')).toHaveClass 'selected'
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
SelectList = require 'select-list'
|
||||
Editor = require 'editor'
|
||||
$ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class EventPalette extends SelectList
|
||||
@@ -15,25 +16,36 @@ class EventPalette extends SelectList
|
||||
|
||||
filterKey: 'eventDescription'
|
||||
|
||||
previouslyFocusedElement: null
|
||||
keyBindings: null
|
||||
|
||||
initialize: (@rootView) ->
|
||||
@on 'event-palette:toggle', => @cancel()
|
||||
super
|
||||
|
||||
attach: ->
|
||||
@previouslyFocusedElement = $(':focus')
|
||||
@keyBindings = _.losslessInvert(keymap.bindingsForElement(@previouslyFocusedElement))
|
||||
|
||||
events = []
|
||||
for eventName, eventDescription of @previouslyFocusedElement.events()
|
||||
events.push({eventName, eventDescription}) if eventDescription
|
||||
|
||||
events = _.sortBy events, (e) -> e.eventDescription
|
||||
|
||||
@setArray(events)
|
||||
@appendTo(@rootView)
|
||||
@miniEditor.setText('')
|
||||
@miniEditor.focus()
|
||||
|
||||
itemForElement: ({eventName, eventDescription}) ->
|
||||
keyBindings = @keyBindings
|
||||
$$ ->
|
||||
@li class: 'event', 'data-event-name': eventName, =>
|
||||
@div eventDescription, class: 'event-description'
|
||||
@div eventName, class: 'event-name'
|
||||
for binding in keyBindings[eventName] ? []
|
||||
@div binding, class: 'key-binding'
|
||||
@div class: 'clear-float'
|
||||
|
||||
confirmed: ({eventName}) ->
|
||||
|
||||
@@ -7,12 +7,28 @@
|
||||
max-height: 300px;
|
||||
}
|
||||
|
||||
.event-palette ol li {
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.event-palette ol .event-description {
|
||||
float: left;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.event-palette ol .event-name {
|
||||
.event-palette ol .event-name, .event-palette ol .key-binding {
|
||||
float: right;
|
||||
display: inline-block;
|
||||
margin-right: .5em;
|
||||
color: #ddd;
|
||||
-webkit-border-radius: 3px;
|
||||
padding: 0 4px;
|
||||
}
|
||||
|
||||
.event-palette ol .event-name {
|
||||
background: rgba(0, 0, 0, .2);
|
||||
}
|
||||
|
||||
.event-palette ol .key-binding {
|
||||
background: rgba(255, 255, 255, .1);
|
||||
}
|
||||
@@ -61,4 +61,11 @@ _.mixin
|
||||
words.map(_.capitalize).join(' ')
|
||||
|
||||
capitalize: (word) ->
|
||||
word[0].toUpperCase() + word[1..]
|
||||
word[0].toUpperCase() + word[1..]
|
||||
|
||||
losslessInvert: (hash) ->
|
||||
inverted = {}
|
||||
for key, value of hash
|
||||
inverted[value] ?= []
|
||||
inverted[value].push(key)
|
||||
inverted
|
||||
Reference in New Issue
Block a user