From e5a4b4c5f4988b8424bd2f0221124b17b525c651 Mon Sep 17 00:00:00 2001 From: sibiraj-s Date: Wed, 17 Mar 2021 21:55:56 +0530 Subject: [PATCH] feat: line break on Shift-Enter --- src/lib/defaultPlugins.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/defaultPlugins.ts b/src/lib/defaultPlugins.ts index 28ddb48a..3a118500 100644 --- a/src/lib/defaultPlugins.ts +++ b/src/lib/defaultPlugins.ts @@ -1,7 +1,7 @@ import { NodeType, Schema } from 'prosemirror-model'; import { Plugin } from 'prosemirror-state'; import { keymap } from 'prosemirror-keymap'; -import { toggleMark, baseKeymap } from 'prosemirror-commands'; +import { toggleMark, baseKeymap, chainCommands, exitCode } from 'prosemirror-commands'; import { splitListItem, liftListItem, sinkListItem } from 'prosemirror-schema-list'; import { history, undo, redo } from 'prosemirror-history'; import { @@ -103,6 +103,12 @@ const getKeyboardShortcuts = (schema: Schema, options: ShortcutOptions) => { }), keymap({ Enter: splitListItem(schema.nodes.list_item), + 'Shift-Enter': chainCommands(exitCode, (state, dispatch) => { + const tr = state.tr; + const br = schema.nodes.hard_break; + dispatch(tr.replaceSelectionWith(br.create()).scrollIntoView()); + return true; + }), 'Mod-[': liftListItem(schema.nodes.list_item), 'Mod-]': sinkListItem(schema.nodes.list_item), Tab: sinkListItem(schema.nodes.list_item)