Merge branch 'master' into global-find

Conflicts:
	spec/extensions/command-panel-spec.coffee
This commit is contained in:
Nathan Sobo
2012-07-23 11:31:26 -06:00
parent 7f5c588723
commit a0e3ce5f1c
3 changed files with 42 additions and 29 deletions

View File

@@ -27,28 +27,43 @@ describe "CommandPanel", ->
newRootView.remove()
describe "when toggle-command-panel is triggered on the root view", ->
it "toggles the command panel", ->
describe "when command-panel:toggle is triggered on the root view", ->
beforeEach ->
rootView.attachToDom()
expect(rootView.find('.command-panel')).not.toExist()
expect(rootView.getActiveEditor().isFocused).toBeTruthy()
expect(commandPanel.miniEditor.isFocused).toBeFalsy()
rootView.trigger 'command-panel:toggle'
expect(rootView.find('.command-panel').view()).toBe commandPanel
expect(commandPanel.miniEditor.isFocused).toBeTruthy()
commandPanel.miniEditor.insertText 's/war/peace/g'
describe "when the command panel is visible", ->
beforeEach ->
commandPanel.attach()
rootView.trigger 'command-panel:toggle'
expect(rootView.find('.command-panel')).not.toExist()
expect(rootView.getActiveEditor().isFocused).toBeTruthy()
expect(commandPanel.miniEditor.isFocused).toBeFalsy()
describe "when the command panel is focused", ->
it "closes the command panel", ->
expect(commandPanel.miniEditor.hiddenInput).toMatchSelector ':focus'
rootView.trigger 'command-panel:toggle'
expect(commandPanel.hasParent()).toBeFalsy()
describe "when the command panel is not focused", ->
it "focuses the command panel", ->
rootView.focus()
expect(commandPanel.miniEditor.hiddenInput).not.toMatchSelector ':focus'
rootView.trigger 'command-panel:toggle'
expect(commandPanel.hasParent()).toBeTruthy()
expect(commandPanel.miniEditor.hiddenInput).toMatchSelector ':focus'
describe "when the command panel is not visible", ->
it "shows and focuses the command panel", ->
expect(commandPanel.hasParent()).toBeFalsy()
rootView.trigger 'command-panel:toggle'
expect(commandPanel.hasParent()).toBeTruthy()
describe "when command-panel:unfocus is triggered on the command panel", ->
it "returns focus to the root view but does not hide the command panel", ->
rootView.attachToDom()
commandPanel.attach()
expect(commandPanel.miniEditor.hiddenInput).toMatchSelector ':focus'
commandPanel.trigger 'command-panel:unfocus'
expect(commandPanel.hasParent()).toBeTruthy()
expect(commandPanel.miniEditor.hiddenInput).not.toMatchSelector ':focus'
rootView.trigger 'command-panel:toggle'
expect(rootView.find('.command-panel').view()).toBe commandPanel
expect(commandPanel.miniEditor.isFocused).toBeTruthy()
expect(commandPanel.miniEditor.getText()).toBe ''
expect(commandPanel.miniEditor.getCursorScreenPosition()).toEqual [0, 0]
describe "when command-panel:repeat-relative-address is triggered on the root view", ->
it "repeats the last search command if there is one", ->
@@ -73,7 +88,7 @@ describe "CommandPanel", ->
rootView.trigger 'command-panel:repeat-relative-address'
expect(editor.getSelection().getBufferRange()).toEqual [[3,31], [3,38]]
describe "when command-pane:repeat-relative-address-in-reverse is triggered on the root view", ->
describe "when command-panel:repeat-relative-address-in-reverse is triggered on the root view", ->
it "it repeats the last relative address in the reverse direction", ->
rootView.trigger 'command-panel:repeat-relative-address-in-reverse'
@@ -120,13 +135,6 @@ describe "CommandPanel", ->
expect(commandPanel.miniEditor.getText()).toBe "Xx/"
expect(commandPanel.miniEditor.getCursorBufferPosition()).toEqual [0, 3]
describe "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.miniEditor.hiddenInput.trigger keydownEvent('escape')
expect(rootView.find('.command-panel')).not.toExist()
describe "when return is pressed on the panel's editor", ->
describe "if the command has an immediate effect", ->
it "executes it immediately on the current buffer", ->

View File

@@ -44,6 +44,7 @@ class CommandPanel extends View
@commandInterpreter = new CommandInterpreter(@rootView.project)
@history = []
@on 'command-panel:unfocus', => @rootView.focus()
@rootView.on 'command-panel:toggle', => @toggle()
@rootView.on 'command-panel:execute', => @execute()
@rootView.on 'command-panel:find-in-file', => @attach("/")
@@ -57,8 +58,12 @@ class CommandPanel extends View
@miniEditor.on 'move-down', => @navigateForwardInHistory()
toggle: ->
if @parent().length then @detach() else @attach()
false
if @miniEditor.isFocused
@detach()
@rootView.focus()
else
@attach() unless @hasParent()
@miniEditor.focus()
attach: (text='') ->
@rootView.append(this)

View File

@@ -6,7 +6,7 @@ window.keymap.bindKeys '*'
window.keymap.bindKeys '.command-panel .editor input',
'meta-w': 'command-panel:toggle'
escape: 'command-panel:toggle'
escape: 'command-panel:unfocus'
enter: 'command-panel:execute'
window.keymap.bindKeys '.editor',