1.21 gigawatts
1.21 gigawatts

Reputation: 17762

Correct syntax for adding a command

Did the syntax for command objects change? I have been using the following:

editor.addCommand({
    name: "find",
    bindKey: {win: "Ctrl-F", mac: "Cmd-F"},
    exec: findKeyboardHandler});

Upvotes: 0

Views: 3103

Answers (2)

Danial
Danial

Reputation: 1614

To call addCommand, you have to call commands:

editor.commands.addCommand({
    name: 'quit',
    exec: function(){
        yourQuitFunctionHere();
    }
});

then you can use the command for keybindings or exec directly:

editor.execCommand('quit');

Upvotes: 0

a user
a user

Reputation: 24104

Ace command syntax had not changed for a long time

  • All of Command, cmd, Cmd work the same see ace/lib/keys.js#L51-L52
  • keybindings are not case sensitive
  • if keybinding is already defined, the new one will be added to command stack, and the last added one will be called first, if it is not available the next one will be added.
  • command name is unique, if a command with same name exists, old one will be removed.
  • listener is added to the bubble phase ace/lib/event.js#L348
  • there are no reserved names, but using command named __proto__, will break keyboard/hash_handler.js#L40
  • command always gets two arguments, editor and args object ace/commands/command_manager.js#L24

Upvotes: 4

Related Questions