From c68d852f7926ff4c0905dd2e07d717861ab4174d Mon Sep 17 00:00:00 2001 From: Samuel Gyger Date: Mon, 6 May 2024 01:01:09 -0700 Subject: [PATCH] keymap: change to support hard-breaks Allows for Shift-Enter to create a hard break. This follows the implementation of the prosemirror sample. https://github.com/ProseMirror/prosemirror-example-setup/blob/master/src/keymap.ts --- script/plugins/Keymap/keymap.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/script/plugins/Keymap/keymap.js b/script/plugins/Keymap/keymap.js index 7ff64383..f652efe5 100644 --- a/script/plugins/Keymap/keymap.js +++ b/script/plugins/Keymap/keymap.js @@ -1,6 +1,6 @@ import { keymap } from 'prosemirror-keymap'; import { splitListItem, sinkListItem, liftListItem } from 'prosemirror-schema-list'; -import { baseKeymap, chainCommands } from 'prosemirror-commands'; +import { baseKeymap, chainCommands, exitCode } from 'prosemirror-commands'; import { redo, undo } from 'prosemirror-history'; @@ -29,12 +29,28 @@ function getKeymapPlugin(schema) { 'Shift-Tab': liftListItem(schema.nodes.list_item), }; + const br = schema.nodes.hard_break; + const cmd = chainCommands(exitCode, (state, dispatch) => { + if (dispatch) dispatch(state.tr.replaceSelectionWith(br.create()).scrollIntoView()); + return true; + }); + + const hardBreakKeymap = { + 'Mod-Enter': cmd, + 'Shift-Enter': cmd, + }; + + if (isMac) { + hardBreakKeymap['Ctrl-Enter'] = cmd; + } + const mergedKeymap = { ...baseKeymap, ...customKeymap, ...combinedKeymapUnion, ...historyKeymap, ...indentationKeymap, + ...hardBreakKeymap, }; return keymap(mergedKeymap);