Plugin keyboard shortcut

This example shows how a plugin registers a keyboard shortcut for its command with hotkeys.add.

Code

<div id="entry-plugin-shortcut"></div>
const app = Redactor('#entry-plugin-shortcut', {
    plugins: ['greetingShortcut']
});
class GreetingShortcutPlugin {
    start() {
        this.app.toolbar.add('greetingShortcut', {
            title: 'Insert greeting',
            command: 'greetingShortcut.insert',
            position: { after: 'add' }
        });

        this.app.hotkeys.add('ctrl+shift+g, meta+shift+g', {
            title: 'Insert greeting',
            name: 'meta+shift+g',
            command: 'greetingShortcut.insert'
        });
    }

    insert() {
        const inserter = this.app.getService('inserter');
        inserter.insertHtml('<p>Hello from shortcut!</p>', { caret: 'end' });
    }
}

Redactor.addPlugin('greetingShortcut', GreetingShortcutPlugin);