Custom Keyboard Bindings/Shortcuts

2,792 views
Skip to first unread message

Bauer UK

unread,
Feb 5, 2011, 7:18:58 PM2/5/11
to ace-d...@googlegroups.com
Suppose I'm initialising an editor as so:

// init editor
editor = ace.edit(id);            

// set the theme
editor.setTheme("ace/theme/twilight");

// generate the css mode
css_mode = require("ace/mode/css").Mode;

// set the mode to css
editor.getSession().setMode(new css_mode());

What's the best way to then go about binding a key to the editor? For the sake of example, Ctrl-S.

Aleksey Gureiev

unread,
Feb 6, 2011, 2:38:51 AM2/6/11
to ace-d...@googlegroups.com
From what I saw, key bindings are defined in keybindings_default folder all in one go. I'm trying to make the TextMate version, but many combinations refuse to work. Interestingly, Ctrl-S is one of them.

Bauer UK

unread,
Feb 6, 2011, 6:55:43 AM2/6/11
to ace-d...@googlegroups.com

On Sunday, February 6, 2011 7:38:51 AM UTC, Aleksey Gureiev wrote:
From what I saw, key bindings are defined in keybindings_default folder all in one go. 

Ah, I was hoping there would be a programmatic solution. In this particular instance, I'm injecting the editor to a page in a Google Chrome extension. 

Aleksey Gureiev

unread,
Feb 6, 2011, 8:32:58 AM2/6/11
to ace-d...@googlegroups.com
This may be helpful: http://ui.ajax.org/#docs/object.apf.method.registerhotkey

I'm not totally sure yet, but it looks like Ace uses APF.

Harutyun Amirjanyan

unread,
Feb 6, 2011, 1:35:56 PM2/6/11
to Ajax.org Cloud9 Editor (Ace)
have you looked into demo? it might help
var HashHandler = require("ace/keyboard/
hash_handler").HashHandler;
custom: new HashHandler({
"mycommand": "Alt-.|Alt-/|alt-\\|Ctrl-s"
})
editor.setKeyboardHandler(keybindings[value]);
Message has been deleted

Harsha pps

unread,
Dec 14, 2016, 10:50:11 AM12/14/16
to Ajax.org Cloud9 Editor (Ace)
 editor.commands.addCommand({
                    name
: "myCommand",
                    bindKey
: { win: "Ctrl-S", mac: "Command-S" },
                   
exec: function (editor) {
                              alert
("Ctrl-S has been pressed!");
                   
}
});
Reply all
Reply to author
Forward
0 new messages