Monaco-editor: Binding multiple keycode command

Created on 30 Jun 2016  路  2Comments  路  Source: microsoft/monaco-editor

Hi Team,

I understand that binding a single key can be easily achieved using this following code:

var myBinding = editor.addCommand(monaco.KeyCode.F9, function() {
    alert('F9 pressed!');
});

However is it also possible to bind multiple key code such as Ctrl+S for save?

Within monaco.d.ts I found that the addCommand editor within the IStandaloneCodeEditor only receives a single number keybinding:

export interface IStandaloneCodeEditor extends ICodeEditor {
        addCommand(keybinding: number, handler: ICommandHandler, context: string): string;
        createContextKey<T>(key: string, defaultValue: T): IKeybindingContextKey<T>;
        addAction(descriptor: IActionDescriptor): void;
}

I might have reading it wrong since I also found that the right click context menu shown some key combination code:
image

Thanks

Most helpful comment

You bitwise OR them together:

var myBinding = editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S, function() {
    alert('SAVE pressed!');
});

Though look at Issue #25 if you are working with Firefox and issuing an alert. :)

All 2 comments

You bitwise OR them together:

var myBinding = editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S, function() {
    alert('SAVE pressed!');
});

Though look at Issue #25 if you are working with Firefox and issuing an alert. :)

Thanks for your help @ptyork

Was this page helpful?
0 / 5 - 0 ratings