1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-07 23:03:00 +03:00

MD Editor: Added plaintext/cm switching

Also aligned the construction of the inputs where possible.
This commit is contained in:
Dan Brown
2025-07-22 10:34:29 +01:00
parent 6b4b500a33
commit d55db06c01
6 changed files with 82 additions and 43 deletions

View File

@@ -1,5 +1,4 @@
import {MarkdownEditor} from "./index.mjs";
import {KeyBinding} from "@codemirror/view";
export type MarkdownEditorShortcutMap = Record<string, () => void>;
@@ -42,22 +41,3 @@ export function provideShortcutMap(editor: MarkdownEditor): MarkdownEditorShortc
return shortcuts;
}
/**
* Get the editor shortcuts in CodeMirror keybinding format.
*/
export function provideKeyBindings(editor: MarkdownEditor): KeyBinding[] {
const shortcuts = provideShortcutMap(editor);
const keyBindings = [];
const wrapAction = (action: ()=>void) => () => {
action();
return true;
};
for (const [shortcut, action] of Object.entries(shortcuts)) {
keyBindings.push({key: shortcut, run: wrapAction(action), preventDefault: true});
}
return keyBindings;
}