]> BookStack Code Mirror - bookstack/blob - resources/js/markdown/shortcuts.ts
MD Editor: Added plaintext/cm switching
[bookstack] / resources / js / markdown / shortcuts.ts
1 import {MarkdownEditor} from "./index.mjs";
2
3 export type MarkdownEditorShortcutMap = Record<string, () => void>;
4
5 /**
6  * Provide shortcuts for the editor instance.
7  */
8 export function provideShortcutMap(editor: MarkdownEditor): MarkdownEditorShortcutMap {
9     const shortcuts: MarkdownEditorShortcutMap = {};
10
11     // Insert Image shortcut
12     shortcuts['Shift-Mod-i'] = () => editor.actions.insertImage();
13
14     // Save draft
15     shortcuts['Mod-s'] = () => window.$events.emit('editor-save-draft');
16
17     // Save page
18     shortcuts['Mod-Enter'] = () => window.$events.emit('editor-save-page');
19
20     // Show link selector
21     shortcuts['Shift-Mod-k'] = () => editor.actions.showLinkSelector();
22
23     // Insert Link
24     shortcuts['Mod-k'] = () => editor.actions.insertLink();
25
26     // FormatShortcuts
27     shortcuts['Mod-1'] = () => editor.actions.replaceLineStart('##');
28     shortcuts['Mod-2'] = () => editor.actions.replaceLineStart('###');
29     shortcuts['Mod-3'] = () => editor.actions.replaceLineStart('####');
30     shortcuts['Mod-4'] = () => editor.actions.replaceLineStart('#####');
31     shortcuts['Mod-5'] = () => editor.actions.replaceLineStart('');
32     shortcuts['Mod-d'] = () => editor.actions.replaceLineStart('');
33     shortcuts['Mod-6'] = () => editor.actions.replaceLineStart('>');
34     shortcuts['Mod-q'] = () => editor.actions.replaceLineStart('>');
35     shortcuts['Mod-7'] = () => editor.actions.wrapSelection('\n```\n', '\n```');
36     shortcuts['Mod-8'] = () => editor.actions.wrapSelection('`', '`');
37     shortcuts['Shift-Mod-e'] = () => editor.actions.wrapSelection('`', '`');
38     shortcuts['Mod-9'] = () => editor.actions.cycleCalloutTypeAtSelection();
39     shortcuts['Mod-p'] = () => editor.actions.replaceLineStart('-');
40     shortcuts['Mod-o'] = () => editor.actions.replaceLineStartForOrderedList();
41
42     return shortcuts;
43 }