Pull out command-palette package into a separate repo

This commit is contained in:
Kevin Sawicki
2013-08-13 11:42:07 -07:00
parent 58a938b3f1
commit 257722f82e
5 changed files with 1 additions and 167 deletions

View File

@@ -71,6 +71,7 @@
"bookmarks": "0.1.0",
"bracket-matcher": "0.1.0",
"command-logger": "0.1.0",
"command-palette": "0.1.0",
"editor-stats": "0.1.0",
"gfm": "0.1.0",
"git-diff": "0.1.0",

View File

@@ -1,5 +0,0 @@
'body, .command-palette .editor':
'meta-p': 'command-palette:toggle'
'.command-palette .editor':
'meta-p': 'command-palette:toggle'

View File

@@ -1,59 +0,0 @@
{$$} = require 'space-pen'
SelectList = require 'select-list'
$ = require 'jquery'
_ = require 'underscore'
module.exports =
class CommandPaletteView extends SelectList
@activate: ->
new CommandPaletteView
@viewClass: ->
"#{super} command-palette overlay from-top"
filterKey: 'eventDescription'
keyBindings: null
initialize: ->
super
rootView.command 'command-palette:toggle', => @toggle()
toggle: ->
if @hasParent()
@cancel()
else
@attach()
attach: ->
super
if @previouslyFocusedElement[0]
@eventElement = @previouslyFocusedElement
else
@eventElement = rootView
@keyBindings = _.losslessInvert(keymap.bindingsForElement(@eventElement))
events = []
for eventName, eventDescription of _.extend($(window).events(), @eventElement.events())
events.push({eventName, eventDescription}) if eventDescription
events = _.sortBy events, (e) -> e.eventDescription
@setArray(events)
@appendTo(rootView)
@miniEditor.focus()
itemForElement: ({eventName, eventDescription}) ->
keyBindings = @keyBindings
$$ ->
@li class: 'event', 'data-event-name': eventName, =>
@span eventDescription, title: eventName
@div class: 'right', =>
for binding in keyBindings[eventName] ? []
@kbd binding, class: 'key-binding'
confirmed: ({eventName}) ->
@cancel()
@eventElement.trigger(eventName)

View File

@@ -1,3 +0,0 @@
'main': './lib/command-palette-view'
'description': 'Find and run available commands.'
'activationEvents': 'command-palette:toggle'

View File

@@ -1,100 +0,0 @@
RootView = require 'root-view'
CommandPalette = require 'command-palette/lib/command-palette-view'
$ = require 'jquery'
_ = require 'underscore'
describe "CommandPalette", ->
[palette] = []
beforeEach ->
window.rootView = new RootView
rootView.open('sample.js')
atom.activatePackage("command-palette")
rootView.attachToDom().focus()
rootView.trigger 'command-palette:toggle'
palette = rootView.find('.command-palette').view()
afterEach ->
rootView.remove()
describe "when command-palette:toggle is triggered on the root view", ->
it "shows a list of all valid command descriptions, names, and keybindings for the previously focused element", ->
keyBindings = _.losslessInvert(keymap.bindingsForElement(rootView.getActiveView()))
for eventName, description of rootView.getActiveView().events()
eventLi = palette.list.children("[data-event-name='#{eventName}']")
if description
expect(eventLi).toExist()
expect(eventLi.find('span')).toHaveText(description)
expect(eventLi.find('span').attr('title')).toBe(eventName)
for binding in keyBindings[eventName] ? []
expect(eventLi.find(".key-binding:contains(#{binding})")).toExist()
else
expect(eventLi).not.toExist()
it "displays all commands registerd on the window", ->
editorEvents = rootView.getActiveView().events()
windowEvents = $(window).events()
expect(_.isEmpty(windowEvents)).toBeFalsy()
for eventName, description of windowEvents
eventLi = palette.list.children("[data-event-name='#{eventName}']")
description = editorEvents[eventName] unless description
if description
expect(eventLi).toExist()
expect(eventLi.find('span')).toHaveText(description)
expect(eventLi.find('span').attr('title')).toBe(eventName)
else
expect(eventLi).not.toExist()
it "focuses the mini-editor and selects the first command", ->
expect(palette.miniEditor.isFocused).toBeTruthy()
expect(palette.find('.event:first')).toHaveClass 'selected'
it "clears the previous mini editor text", ->
palette.miniEditor.setText('hello')
palette.trigger 'command-palette:toggle'
rootView.trigger 'command-palette:toggle'
expect(palette.miniEditor.getText()).toBe ''
describe "when command-palette:toggle is triggered on the open command palette", ->
it "focus the root view and detaches the command palette", ->
expect(palette.hasParent()).toBeTruthy()
palette.trigger 'command-palette:toggle'
expect(palette.hasParent()).toBeFalsy()
expect(rootView.getActiveView().isFocused).toBeTruthy()
describe "when the command palette is cancelled", ->
it "focuses the root view and detaches the command palette", ->
expect(palette.hasParent()).toBeTruthy()
palette.cancel()
expect(palette.hasParent()).toBeFalsy()
expect(rootView.getActiveView().isFocused).toBeTruthy()
describe "when an command selection is confirmed", ->
it "detaches the palette, then focuses the previously focused element and emits the selected command on it", ->
eventHandler = jasmine.createSpy 'eventHandler'
activeEditor = rootView.getActiveView()
{eventName} = palette.array[5]
activeEditor.preempt eventName, eventHandler
palette.confirmed(palette.array[5])
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('span')).toHaveText(description)
expect(eventLi.find('span').attr('title')).toBe(eventName)
for binding in keyBindings[eventName] ? []
expect(eventLi.find(".key-binding:contains(#{binding})")).toExist()
else
expect(eventLi).not.toExist()