2 * Provide shortcuts for the given codemirror instance.
3 * @param {MarkdownEditor} editor
4 * @param {String} metaKey
5 * @returns {Object<String, Function>}
7 export function provide(editor, metaKey) {
10 // Insert Image shortcut
11 shortcuts[`${metaKey}-Alt-I`] = function(cm) {
12 const selectedText = cm.getSelection();
13 const newText = ``;
14 const cursorPos = cm.getCursor('from');
15 cm.replaceSelection(newText);
16 cm.setCursor(cursorPos.line, cursorPos.ch + newText.length -1);
20 shortcuts[`${metaKey}-S`] = cm => window.$events.emit('editor-save-draft');
23 shortcuts[`${metaKey}-Enter`] = cm => window.$events.emit('editor-save-page');
26 shortcuts[`Shift-${metaKey}-K`] = cm => editor.actions.showLinkSelector();
29 shortcuts[`${metaKey}-K`] = cm => editor.actions.insertLink();
32 shortcuts[`${metaKey}-1`] = cm => editor.actions.replaceLineStart('##');
33 shortcuts[`${metaKey}-2`] = cm => editor.actions.replaceLineStart('###');
34 shortcuts[`${metaKey}-3`] = cm => editor.actions.replaceLineStart('####');
35 shortcuts[`${metaKey}-4`] = cm => editor.actions.replaceLineStart('#####');
36 shortcuts[`${metaKey}-5`] = cm => editor.actions.replaceLineStart('');
37 shortcuts[`${metaKey}-D`] = cm => editor.actions.replaceLineStart('');
38 shortcuts[`${metaKey}-6`] = cm => editor.actions.replaceLineStart('>');
39 shortcuts[`${metaKey}-Q`] = cm => editor.actions.replaceLineStart('>');
40 shortcuts[`${metaKey}-7`] = cm => editor.actions.wrapSelection('\n```\n', '\n```');
41 shortcuts[`${metaKey}-8`] = cm => editor.actions.wrapSelection('`', '`');
42 shortcuts[`Shift-${metaKey}-E`] = cm => editor.actions.wrapSelection('`', '`');
43 shortcuts[`${metaKey}-9`] = cm => editor.actions.wrapSelection('<p class="callout info">', '</p>');
44 shortcuts[`${metaKey}-P`] = cm => editor.actions.replaceLineStart('-')
45 shortcuts[`${metaKey}-O`] = cm => editor.actions.replaceLineStartForOrderedList()