Unable to add multiple commands


#1

Hello.
I am creating a package with two commands. Oddly, first action gets executes only after second command has been executed - so I am failing to make first action to run without triggering the second.

Steps to reproduce:

  1. Execute First action -> nothing happens,
  2. Execute Second action -> adds text to Editor;
  3. Execute First action again -> adds text to Editor;

Am I missing something here?
Thank you.

main.js:

'use babel';
import { CompositeDisposable } from 'atom';

export default {
    subscriptions: null,
    activate(state) {
        // Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
        this.subscriptions = new CompositeDisposable();

        // Register command that toggles this view
        this.subscriptions.add(atom.commands.add('atom-workspace', {
            'test:firstAction': () => this.writeText(
                "Action Number One"),
        }));
        this.subscriptions.add(atom.commands.add('atom-workspace', {
            'test:secondAction': () => this.writeText(
                "Action Number Two")
        }));
    },
    writeText(text) {
        let editor = atom.workspace.getActiveTextEditor();
        editor.insertText(text)
    },
    deactivate() {
        this.subscriptions.dispose();
    }
};

Also, adding multiple commands in one go doesn’t solve the issue as well

this.subscriptions.add(atom.commands.add('atom-workspace', {
    'test:firstAction': () => this.writeText( "Action Number One"),
	'test:secondAction': () => this.writeText( "Action Number Two"),
}));

package.json

"activationCommands": {
    "atom-workspace": "test:firstAction",
    "atom-workspace": "test:secondAction"
},

menu.json

{
    "context-menu": {
        "atom-text-editor": [{
            "label": "First Action",
            "command": "test:firstAction"
        }]
    },
    "menu": [{
        "label": "Packages",
        "submenu": [{
            "label": "Test",
            "submenu": [{
                "label": "First Action",
                "command": "test:firstAction"
            }, {
                "label": "Second Action",
                "command": "test:secondAction"
            }]
        }]
    }]
}

#2

Ok, after some more trial and error I find the issue was in package.json file. Which makes sense.
Changing this:

"activationCommands": {
    "atom-workspace": "test:firstAction",
    "atom-workspace": "test:secondAction"
},

to this:

"activationCommands": {
	"atom-workspace": [
		"test:firstAction",
		"test:secondAction"
	]
},

solved the issue.


#3

Do you feel like you want to use activationCommands? You don’t have to. If you don’t, the package will be activated when Atom is loaded, and if it’s a smallish package, there’s not a substantial reason for deferring activation.


#4

Ohh, I didn’t know I can leave activationCommands out from package.json. Sweet.
Thanks @DamnedScholar