From a4c25dc678a4bb138f0d7a8e079ef1f5ac5ae293 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 28 Mar 2012 16:11:44 -0700 Subject: [PATCH] Flash red when entering a malformed command in the command panel --- spec/atom/command-panel-spec.coffee | 13 +++++++++++++ src/atom/command-panel.coffee | 13 ++++++++++++- static/command-panel.css | 5 +++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/spec/atom/command-panel-spec.coffee b/spec/atom/command-panel-spec.coffee index 034975803..829ff4e66 100644 --- a/spec/atom/command-panel-spec.coffee +++ b/spec/atom/command-panel-spec.coffee @@ -55,6 +55,19 @@ describe "CommandPanel", -> expect(commandPanel.execute).toHaveBeenCalled() + describe "if the command is malformed", -> + it "adds and removes an error class to the command panel and does not close it", -> + rootView.trigger 'command-panel:toggle' + commandPanel.editor.insertText 'garbage-command!!' + + commandPanel.editor.trigger keydownEvent('enter') + expect(commandPanel.parent()).toExist() + expect(commandPanel).toHaveClass 'error' + + advanceClock 400 + + expect(commandPanel).not.toHaveClass 'error' + describe ".execute()", -> it "executes the command and closes the command panel", -> rootView.activeEditor().setText("i hate love") diff --git a/src/atom/command-panel.coffee b/src/atom/command-panel.coffee index e0a0cab2f..40ffbc63b 100644 --- a/src/atom/command-panel.coffee +++ b/src/atom/command-panel.coffee @@ -1,6 +1,7 @@ {View} = require 'space-pen' CommandInterpreter = require 'command-interpreter' Editor = require 'editor' +{SyntaxError} = require('pegjs').parser module.exports = class CommandPanel extends View @@ -41,7 +42,17 @@ class CommandPanel extends View @rootView.activeEditor().focus() execute: -> - @commandInterpreter.eval(@rootView.activeEditor(), @editor.getText()) + try + @commandInterpreter.eval(@rootView.activeEditor(), @editor.getText()) + catch error + if error instanceof SyntaxError + @addClass 'error' + removeErrorClass = => @removeClass 'error' + window.setTimeout(removeErrorClass, 200) + return + else + throw error + @hide() repeatRelativeAddress: -> diff --git a/static/command-panel.css b/static/command-panel.css index 8b520bb11..44839c276 100644 --- a/static/command-panel.css +++ b/static/command-panel.css @@ -4,6 +4,11 @@ background: #515151; display: -webkit-box; padding: 3px; + -webkit-transition: background 200ms ease-out; +} + +.command-panel.error { + background: #991212; } .command-panel .prompt {