Skip to content

Instantly share code, notes, and snippets.

@joemccann
Created November 12, 2011 16:31
Show Gist options
  • Save joemccann/1360777 to your computer and use it in GitHub Desktop.
Save joemccann/1360777 to your computer and use it in GitHub Desktop.
Ace Editor Add Command Fail
function bindKeyboard(){
// CMD+s TO SAVE DOC
var command = {
name: "save",
bindKey: {
mac: "Command-S",
win: "Ctrl-S"
},
exec: function(){
saveFile() // this function is defined elsewhere, but available in outer scope.
}
}
// Tried this first:
editor.commands.addCommand(command)
// But this fails as editor.commands is undefined
// Then I tried this:
var cm = new CommandManager("mac", [command]);
// But this fails because CommandManager is not defined either.
}
@fjakobs
Copy link

fjakobs commented Nov 13, 2011

'editor.commands.addCommand' is the correct way to do it. 'editor.commands' is rather new though.

@joemccann
Copy link
Author

The problem is that editor.commands is undefined.

So if I actually console.dir(editor) there is no property on the editor object for commands?

@fjakobs
Copy link

fjakobs commented Nov 14, 2011

The one I just pushed to github has it http://ace.ajax.org/build/kitchen-sink.html

type env.editor.commands in the console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment