From 17e20d2fb0c984e77ebff39574b04b6676a9b0e0 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 13 Jun 2012 17:48:51 -0700 Subject: [PATCH 1/3] Change .editor to .miniEditor in command panel specs --- spec/extensions/command-panel-spec.coffee | 53 ++++++++++++----------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/spec/extensions/command-panel-spec.coffee b/spec/extensions/command-panel-spec.coffee index 0ac0f483e..783b3c999 100644 --- a/spec/extensions/command-panel-spec.coffee +++ b/spec/extensions/command-panel-spec.coffee @@ -15,25 +15,25 @@ describe "CommandPanel", -> rootView.attachToDom() expect(rootView.find('.command-panel')).not.toExist() expect(rootView.activeEditor().isFocused).toBeTruthy() - expect(commandPanel.editor.isFocused).toBeFalsy() + expect(commandPanel.miniEditor.isFocused).toBeFalsy() rootView.trigger 'command-panel:toggle' expect(rootView.find('.command-panel').view()).toBe commandPanel - expect(commandPanel.editor.isFocused).toBeTruthy() + expect(commandPanel.miniEditor.isFocused).toBeTruthy() # this is currently assigned dynamically since our css scheme lacks variables - expect(commandPanel.prompt.css('font')).toBe commandPanel.editor.css('font') - commandPanel.editor.insertText 's/war/peace/g' + expect(commandPanel.prompt.css('font')).toBe commandPanel.miniEditor.css('font') + commandPanel.miniEditor.insertText 's/war/peace/g' rootView.trigger 'command-panel:toggle' expect(rootView.find('.command-panel')).not.toExist() expect(rootView.activeEditor().isFocused).toBeTruthy() - expect(commandPanel.editor.isFocused).toBeFalsy() + expect(commandPanel.miniEditor.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] + expect(commandPanel.miniEditor.isFocused).toBeTruthy() + expect(commandPanel.miniEditor.buffer.getText()).toBe '' + expect(commandPanel.miniEditor.getCursorScreenPosition()).toEqual [0, 0] describe "when command-panel:repeat-relative-address is triggered on the root view", -> it "calls .repeatRelativeAddress on the command interpreter with the active editor", -> @@ -49,36 +49,37 @@ describe "CommandPanel", -> commandInterpreter = commandPanel.commandInterpreter expect(commandInterpreter.lastRelativeAddress).toBeUndefined() rootView.trigger 'command-panel:set-selection-as-regex-address' - expect(commandInterpreter.lastRelativeAddress.regex.toString()).toEqual "/\\(items\\)/" + expect(commandInterpreter.lastRelativeAddress.subcommands.length).toBe 1 + expect(commandInterpreter.lastRelativeAddress.subcommands[0].regex.toString()).toEqual "/\\(items\\)/" describe "when command-panel:find-in-file is triggered on an editor", -> it "pre-populates command panel's editor with /", -> rootView.activeEditor().trigger "command-panel:find-in-file" expect(commandPanel.parent).not.toBeEmpty() - expect(commandPanel.editor.getText()).toBe "/" + expect(commandPanel.miniEditor.getText()).toBe "/" 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.editor.trigger keydownEvent('escape') + commandPanel.miniEditor.trigger keydownEvent('escape') expect(rootView.find('.command-panel')).not.toExist() describe "when return is pressed on the panel's editor", -> it "calls execute", -> spyOn(commandPanel, 'execute') rootView.trigger 'command-panel:toggle' - commandPanel.editor.insertText 's/hate/love/g' - commandPanel.editor.trigger keydownEvent('enter') + commandPanel.miniEditor.insertText 's/hate/love/g' + commandPanel.miniEditor.trigger keydownEvent('enter') 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.miniEditor.insertText 'garbage-command!!' - commandPanel.editor.trigger keydownEvent('enter') + commandPanel.miniEditor.trigger keydownEvent('enter') expect(commandPanel.parent()).toExist() expect(commandPanel).toHaveClass 'error' @@ -93,23 +94,23 @@ describe "CommandPanel", -> rootView.trigger 'command-panel:toggle' - commandPanel.editor.trigger 'move-up' - expect(commandPanel.editor.getText()).toBe 's/twinkies/wheatgrass/g' - commandPanel.editor.trigger 'move-up' - expect(commandPanel.editor.getText()).toBe 's/war/peace/g' - commandPanel.editor.trigger 'move-up' - expect(commandPanel.editor.getText()).toBe 's/war/peace/g' - commandPanel.editor.trigger 'move-down' - expect(commandPanel.editor.getText()).toBe 's/twinkies/wheatgrass/g' - commandPanel.editor.trigger 'move-down' - expect(commandPanel.editor.getText()).toBe '' + commandPanel.miniEditor.trigger 'move-up' + expect(commandPanel.miniEditor.getText()).toBe 's/twinkies/wheatgrass/g' + commandPanel.miniEditor.trigger 'move-up' + expect(commandPanel.miniEditor.getText()).toBe 's/war/peace/g' + commandPanel.miniEditor.trigger 'move-up' + expect(commandPanel.miniEditor.getText()).toBe 's/war/peace/g' + commandPanel.miniEditor.trigger 'move-down' + expect(commandPanel.miniEditor.getText()).toBe 's/twinkies/wheatgrass/g' + commandPanel.miniEditor.trigger 'move-down' + expect(commandPanel.miniEditor.getText()).toBe '' describe ".execute()", -> it "executes the command and closes the command panel", -> rootView.activeEditor().setText("i hate love") rootView.activeEditor().getSelection().setBufferRange [[0,0], [0,Infinity]] rootView.trigger 'command-panel:toggle' - commandPanel.editor.insertText 's/hate/love/' + commandPanel.miniEditor.insertText 's/hate/love/' commandPanel.execute() expect(rootView.activeEditor().getText()).toBe "i love love" expect(rootView.find('.command-panel')).not.toExist() From e7dafec21c3867757410df70310bad9f905b323e Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 13 Jun 2012 17:49:12 -0700 Subject: [PATCH 2/3] Rename command to compositCommand in command interpreter --- src/extensions/command-interpreter.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/extensions/command-interpreter.coffee b/src/extensions/command-interpreter.coffee index 42ad658a4..7e0c91e2c 100644 --- a/src/extensions/command-interpreter.coffee +++ b/src/extensions/command-interpreter.coffee @@ -7,9 +7,9 @@ class CommandInterpreter @parser = PEG.buildParser(fs.read(require.resolve 'command-interpreter/commands.pegjs')) eval: (editor, string) -> - command = @parser.parse(string) - @lastRelativeAddress = command if command.isRelativeAddress() - command.execute(editor) + compositeCommand = @parser.parse(string) + @lastRelativeAddress = compositeCommand if compositeCommand.isRelativeAddress() + compositeCommand.execute(editor) repeatRelativeAddress: (editor) -> @lastRelativeAddress?.execute(editor) From 958a8bf12c00700c13b4ca37ef65e67ec613c979 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 13 Jun 2012 17:49:20 -0700 Subject: [PATCH 3/3] :lipstick: --- src/extensions/command-panel.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extensions/command-panel.coffee b/src/extensions/command-panel.coffee index 7fa0f0fb0..4fb9cfac0 100644 --- a/src/extensions/command-panel.coffee +++ b/src/extensions/command-panel.coffee @@ -42,7 +42,7 @@ class CommandPanel extends View @rootView.on 'command-panel:execute', => @execute() @rootView.on 'command-panel:find-in-file', => @show("/") @rootView.on 'command-panel:repeat-relative-address', => @repeatRelativeAddress() - @rootView.on 'command-panel:set-selection-as-regex-address', => @useSelectionAsLastRelativeAddress() + @rootView.on 'command-panel:set-selection-as-regex-address', => @setSelectionAsLastRelativeAddress() @miniEditor.off 'move-up move-down' @miniEditor.on 'move-up', => @navigateBackwardInHistory() @@ -88,7 +88,7 @@ class CommandPanel extends View repeatRelativeAddress: -> @commandInterpreter.repeatRelativeAddress(@rootView.activeEditor()) - useSelectionAsLastRelativeAddress: -> + setSelectionAsLastRelativeAddress: -> selection = @rootView.activeEditor().getSelectedText() regex = _.escapeRegExp(selection) @commandInterpreter.lastRelativeAddress = new CompositeCommand([new RegexAddress(regex)]) \ No newline at end of file