diff --git a/spec/atom/command-panel-spec.coffee b/spec/atom/command-panel-spec.coffee new file mode 100644 index 000000000..1aee8b8e0 --- /dev/null +++ b/spec/atom/command-panel-spec.coffee @@ -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() + diff --git a/src/atom/command-panel.coffee b/src/atom/command-panel.coffee new file mode 100644 index 000000000..68cc84e06 --- /dev/null +++ b/src/atom/command-panel.coffee @@ -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('') + diff --git a/src/atom/root-view.coffee b/src/atom/root-view.coffee index 46f0d8a68..15d3cf167 100644 --- a/src/atom/root-view.coffee +++ b/src/atom/root-view.coffee @@ -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)) diff --git a/static/command-panel.css b/static/command-panel.css new file mode 100644 index 000000000..728e3e885 --- /dev/null +++ b/static/command-panel.css @@ -0,0 +1,10 @@ +.command-panel { + position: absolute; + bottom: 0; + padding: 3px; + background: #515151; +} + +.command-panel .editor .gutter { + display: none; +}