From 8421e1f7737d4c1548c263f9d7ae7e91ad07d094 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 9 Jun 2022 21:24:11 +0200 Subject: [PATCH] fix: Allow soft breaks in paragraphs with Shift-Enter closes #3276 --- shared/editor/nodes/Paragraph.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/shared/editor/nodes/Paragraph.ts b/shared/editor/nodes/Paragraph.ts index ac9de1cc8..94b08caa4 100644 --- a/shared/editor/nodes/Paragraph.ts +++ b/shared/editor/nodes/Paragraph.ts @@ -1,6 +1,9 @@ import { setBlockType } from "prosemirror-commands"; import { NodeSpec, NodeType, Node as ProsemirrorNode } from "prosemirror-model"; +import { EditorState } from "prosemirror-state"; import { MarkdownSerializerState } from "../lib/markdown/serializer"; +import isNodeActive from "../queries/isNodeActive"; +import { Dispatch } from "../types"; import Node from "./Node"; export default class Paragraph extends Node { @@ -20,6 +23,14 @@ export default class Paragraph extends Node { keys({ type }: { type: NodeType }) { return { "Shift-Ctrl-0": setBlockType(type), + "Shift-Enter": (state: EditorState, dispatch: Dispatch) => { + if (!isNodeActive(type)(state)) { + return false; + } + + dispatch(state.tr.insertText("\n")); + return true; + }, }; }