Meta-: toggles the command palette

This commit is contained in:
Nathan Sobo
2012-03-20 19:59:37 -06:00
parent 28a0f5961a
commit e5eedfb7c7
4 changed files with 80 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
RootView = require 'root-view'
describe "CommandPanel", ->
[rootView, commandPanel] = []
beforeEach ->
rootView = new RootView
rootView.enableKeymap()
commandPanel = rootView.commandPanel
fdescribe "when toggle-command-panel is triggered on the root view", ->
it "toggles the command panel", ->
rootView.attachToDom()
expect(rootView.find('.command-panel')).not.toExist()
expect(rootView.lastActiveEditor().isFocused).toBeTruthy()
expect(commandPanel.editor.isFocused).toBeFalsy()
rootView.trigger 'command-panel:toggle'
expect(rootView.find('.command-panel').view()).toBe commandPanel
expect(commandPanel.editor.isFocused).toBeTruthy()
commandPanel.editor.insertText 's/war/peace/g'
rootView.trigger 'command-panel:toggle'
expect(rootView.find('.command-panel')).not.toExist()
expect(rootView.lastActiveEditor().isFocused).toBeTruthy()
expect(commandPanel.editor.isFocused).toBeFalsy()
rootView.trigger 'command-panel:toggle'
expect(rootView.find('.command-panel').view()).toBe commandPanel
expect(commandPanel.editor.isFocused).toBeTruthy()
expect(commandPanel.editor.buffer.getText()).toBe ''
expect(commandPanel.editor.getCursorScreenPosition()).toEqual [0, 0]
fdescribe "when esc is pressed in the command panel", ->
it "closes the command panel", ->
rootView.trigger 'command-panel:toggle'
expect(rootView.find('.command-panel').view()).toBe commandPanel
commandPanel.editor.trigger keydownEvent('escape')
expect(rootView.find('.command-panel')).not.toExist()

View File

@@ -0,0 +1,26 @@
{View} = require 'space-pen'
Editor = require 'editor'
module.exports =
class CommandPanel extends View
@content: ->
@div class: 'command-panel', =>
@subview 'editor', new Editor
initialize: ({@rootView})->
requireStylesheet 'command-panel.css'
window.keymap.bindKeys '.command-panel .editor',
escape: 'command-panel:toggle'
@rootView.on 'command-panel:toggle', => @toggle()
@editor.addClass 'single-line'
toggle: ->
if @parent().length
@detach()
@rootView.lastActiveEditor().focus()
else
@rootView.append(this)
@editor.focus()
@editor.buffer.setText('')

View File

@@ -8,6 +8,7 @@ Editor = require 'editor'
FileFinder = require 'file-finder'
Project = require 'project'
VimMode = require 'vim-mode'
CommandPanel = require 'command-panel'
module.exports =
class RootView extends View
@@ -25,11 +26,14 @@ class RootView extends View
'meta-s': 'save'
'meta-w': 'close'
'meta-t': 'toggle-file-finder'
'meta-:': 'command-panel:toggle'
'alt-meta-i': 'show-console'
@on 'toggle-file-finder', => @toggleFileFinder()
@on 'show-console', -> window.showConsole()
@commandPanel = new CommandPanel({rootView: this})
createProject: (path) ->
if path
@project = new Project(fs.directory(path))

10
static/command-panel.css Normal file
View File

@@ -0,0 +1,10 @@
.command-panel {
position: absolute;
bottom: 0;
padding: 3px;
background: #515151;
}
.command-panel .editor .gutter {
display: none;
}