CommandPanel shows command errors

This commit is contained in:
Corey Johnson
2012-11-01 15:37:49 -07:00
parent 79a7d35798
commit 9afda88c8c
2 changed files with 37 additions and 6 deletions

View File

@@ -24,9 +24,9 @@ describe "CommandPanel", ->
rootView.attachToDom()
rootView.trigger 'command-panel:toggle'
expect(commandPanel.miniEditor.isFocused).toBeTruthy()
commandPanel.execute('/test')
commandPanel.execute('/.')
expect(commandPanel.history.length).toBe(1)
expect(commandPanel.history[0]).toBe('/test')
expect(commandPanel.history[0]).toBe('/.')
expect(commandPanel.historyIndex).toBe(1)
rootView.trigger 'command-panel:toggle'
expect(commandPanel.miniEditor.isFocused).toBeTruthy()
@@ -40,7 +40,7 @@ describe "CommandPanel", ->
expect(commandPanel.miniEditor.getText()).toBe 'abc'
expect(commandPanel.miniEditor.isFocused).toBeTruthy()
expect(commandPanel.history.length).toBe(1)
expect(commandPanel.history[0]).toBe('/test')
expect(commandPanel.history[0]).toBe('/.')
expect(commandPanel.historyIndex).toBe(1)
rootView2.focus()
@@ -320,6 +320,26 @@ describe "CommandPanel", ->
expect(commandPanel).not.toHaveClass 'error'
describe "if the command returns an error message", ->
beforeEach ->
rootView.attachToDom()
rootView.trigger 'command-panel:toggle'
commandPanel.miniEditor.insertText '/garbage'
expect(commandPanel.errorMessages).not.toBeVisible()
commandPanel.miniEditor.hiddenInput.trigger keydownEvent('enter')
it "adds and removes an error class to the command panel and displays the error message", ->
expect(commandPanel).toBeVisible()
expect(commandPanel.errorMessages).toBeVisible()
expect(commandPanel).toHaveClass 'error'
it "removes the error message when the command-panel is toggled", ->
rootView.trigger 'command-panel:toggle' # off
rootView.trigger 'command-panel:toggle' # on
expect(commandPanel).toBeVisible()
expect(commandPanel.errorMessages).not.toBeVisible()
describe "when the command contains an escaped charachter", ->
it "executes the command with the escaped character (instead of as a backslash followed by the character)", ->
rootView.trigger 'command-panel:toggle'
@@ -416,4 +436,4 @@ describe "CommandPanel", ->
editSession = rootView.getActiveEditSession()
expect(editSession.buffer.getPath()).toBe project.resolve(operation.getPath())
expect(editSession.getSelectedBufferRange()).toEqual operation.getBufferRange()
expect(rootView.focus).toHaveBeenCalled()
expect(rootView.focus).toHaveBeenCalled()

View File

@@ -1,4 +1,4 @@
{View, $$$} = require 'space-pen'
{View, $$, $$$} = require 'space-pen'
CommandInterpreter = require 'command-panel/src/command-interpreter'
RegexAddress = require 'command-panel/src/commands/regex-address'
CompositeCommand = require 'command-panel/src/commands/composite-command'
@@ -67,6 +67,7 @@ class CommandPanel extends View
@command 'core:move-down', => @navigateForwardInHistory()
@previewList.hide()
@errorMessages.hide()
destroy: ->
@previewList.destroy()
@@ -92,6 +93,8 @@ class CommandPanel extends View
@miniEditor.focus()
attach: (text='', options={}) ->
@errorMessages.hide()
focus = options.focus ? true
@rootView.vertical.append(this)
@miniEditor.focus() if focus
@@ -107,11 +110,19 @@ class CommandPanel extends View
@miniEditor.getText().replace /\\(.)/, (match, charachter) -> eval("'\\#{charachter}'")
execute: (command=@escapedCommand())->
@errorMessages.empty()
try
@commandInterpreter.eval(command, @rootView.getActiveEditSession()).done ({operationsToPreview, errorMessages}) =>
@history.push(command)
@historyIndex = @history.length
if operationsToPreview?.length
if errorMessages.length > 0
@flashError()
@errorMessages.show()
@errorMessages.append $$ ->
@li errorMessage for errorMessage in errorMessages
else if operationsToPreview?.length
@previewList.populate(operationsToPreview)
@previewList.focus()
else