How to trigger a command from plugin code?


#1

Hello,

I created a command with atom.workspaceView.command, and it worked fine, apart from not being documented in the api.

Now I would like to add a test for it, but I couldn’t find a way to trigger the command on my code.
Looking at atom code, it [seems that the method sendCommand is under atomWindow, but I can’t find a way to get this object.

In all other packages I checked, the test is done with a keyboard shortcut. But this command don’t have a keyboard shortcut.

Help or pointers would be greatly appreciated.


#2

You can look in my package tabs-to-spaces for some examples:

https://github.com/lee-dohm/tabs-to-spaces/blob/master/spec/tabs-to-spaces-spec.coffee#L25

The method is atom.workspaceView.trigger(). I modeled my specs after the specs in the whitespace package.


#3

Update. Now use:

editorView = atom.views.getView(editor)
atom.commands.dispatch(editorView, 'core:move-left')
```