2 * Provide shortcuts for the editor instance.
3 * @param {MarkdownEditor} editor
4 * @returns {Object<String, Function>}
6 function provide(editor) {
9 // Insert Image shortcut
10 shortcuts['Shift-Mod-i'] = () => editor.actions.insertImage();
13 shortcuts['Mod-s'] = () => window.$events.emit('editor-save-draft');
16 shortcuts['Mod-Enter'] = () => window.$events.emit('editor-save-page');
19 shortcuts['Shift-Mod-k'] = () => editor.actions.showLinkSelector();
22 shortcuts['Mod-k'] = () => editor.actions.insertLink();
25 shortcuts['Mod-1'] = () => editor.actions.replaceLineStart('##');
26 shortcuts['Mod-2'] = () => editor.actions.replaceLineStart('###');
27 shortcuts['Mod-3'] = () => editor.actions.replaceLineStart('####');
28 shortcuts['Mod-4'] = () => editor.actions.replaceLineStart('#####');
29 shortcuts['Mod-5'] = () => editor.actions.replaceLineStart('');
30 shortcuts['Mod-d'] = () => editor.actions.replaceLineStart('');
31 shortcuts['Mod-6'] = () => editor.actions.replaceLineStart('>');
32 shortcuts['Mod-q'] = () => editor.actions.replaceLineStart('>');
33 shortcuts['Mod-7'] = () => editor.actions.wrapSelection('\n```\n', '\n```');
34 shortcuts['Mod-8'] = () => editor.actions.wrapSelection('`', '`');
35 shortcuts['Shift-Mod-e'] = () => editor.actions.wrapSelection('`', '`');
36 shortcuts['Mod-9'] = () => editor.actions.cycleCalloutTypeAtSelection();
37 shortcuts['Mod-p'] = () => editor.actions.replaceLineStart('-');
38 shortcuts['Mod-o'] = () => editor.actions.replaceLineStartForOrderedList();
44 * Get the editor shortcuts in CodeMirror keybinding format.
45 * @param {MarkdownEditor} editor
46 * @return {{key: String, run: function, preventDefault: boolean}[]}
48 export function provideKeyBindings(editor) {
49 const shortcuts = provide(editor);
50 const keyBindings = [];
52 const wrapAction = action => () => {
57 for (const [shortcut, action] of Object.entries(shortcuts)) {
58 keyBindings.push({key: shortcut, run: wrapAction(action), preventDefault: true});