mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Meta-: toggles the command palette
This commit is contained in:
40
spec/atom/command-panel-spec.coffee
Normal file
40
spec/atom/command-panel-spec.coffee
Normal 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()
|
||||
|
||||
26
src/atom/command-panel.coffee
Normal file
26
src/atom/command-panel.coffee
Normal 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('')
|
||||
|
||||
@@ -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
10
static/command-panel.css
Normal file
@@ -0,0 +1,10 @@
|
||||
.command-panel {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
padding: 3px;
|
||||
background: #515151;
|
||||
}
|
||||
|
||||
.command-panel .editor .gutter {
|
||||
display: none;
|
||||
}
|
||||
Reference in New Issue
Block a user