From ee7daa3f4388f1d8912dbdd288f06caacf876ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Thu, 28 Jan 2021 19:56:35 +0100 Subject: [PATCH 1/8] add keepOnSplit option to attributes --- packages/core/src/ExtensionManager.ts | 7 ++-- packages/core/src/commands/splitBlock.ts | 33 ++++++++++++++----- .../helpers/getAttributesFromExtensions.ts | 1 + packages/core/src/types.ts | 1 + .../extension-text-align/src/text-align.ts | 16 ++++----- 5 files changed, 39 insertions(+), 19 deletions(-) diff --git a/packages/core/src/ExtensionManager.ts b/packages/core/src/ExtensionManager.ts index 6b680dbc..96b19c33 100644 --- a/packages/core/src/ExtensionManager.ts +++ b/packages/core/src/ExtensionManager.ts @@ -95,15 +95,18 @@ export default class ExtensionManager { .flat() } + get attributes() { + return getAttributesFromExtensions(this.extensions) + } + get nodeViews() { const { editor } = this const { nodeExtensions } = splitExtensions(this.extensions) - const allAttributes = getAttributesFromExtensions(this.extensions) return Object.fromEntries(nodeExtensions .filter(extension => !!extension.config.addNodeView) .map(extension => { - const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.config.name) + const extensionAttributes = this.attributes.filter(attribute => attribute.type === extension.config.name) const context = { options: extension.options, editor, diff --git a/packages/core/src/commands/splitBlock.ts b/packages/core/src/commands/splitBlock.ts index 5f26c29d..f2236a8e 100644 --- a/packages/core/src/commands/splitBlock.ts +++ b/packages/core/src/commands/splitBlock.ts @@ -15,7 +15,6 @@ function defaultBlockAt(match: ContentMatch) { } export interface SplitBlockOptions { - withAttributes: boolean, withMarks: boolean, } @@ -31,15 +30,35 @@ function keepMarks(state: EditorState) { /** * Forks a new node from an existing node. */ -export const splitBlock = (options: Partial = {}): Command => ({ tr, state, dispatch }) => { +export const splitBlock = (options: Partial = {}): Command => ({ + tr, + state, + dispatch, + editor, +}) => { const defaultOptions: SplitBlockOptions = { - withAttributes: false, withMarks: true, } const config = { ...defaultOptions, ...options } const { selection, doc } = tr const { $from, $to } = selection + const extensionAttributes = editor.extensionManager.attributes + .filter(item => item.type === $from.node().type.name) + + const currentAttributes = $from.node().attrs + const newAttributes = Object.fromEntries(Object + .entries(currentAttributes) + .filter(([name]) => { + const extensionAttribute = extensionAttributes.find(item => item.name === name) + + if (!extensionAttribute) { + return false + } + + return extensionAttribute.attribute.keepOnSplit + })) + if (selection instanceof NodeSelection && selection.node.isBlock) { if (!$from.parentOffset || !canSplit(doc, $from.pos)) { return false @@ -74,9 +93,7 @@ export const splitBlock = (options: Partial = {}): Command => let types = atEnd && deflt ? [{ type: deflt, - attrs: config.withAttributes - ? $from.node().attrs - : {}, + attrs: newAttributes, }] : undefined @@ -91,9 +108,7 @@ export const splitBlock = (options: Partial = {}): Command => types = deflt ? [{ type: deflt, - attrs: config.withAttributes - ? $from.node().attrs - : {}, + attrs: newAttributes, }] : undefined } diff --git a/packages/core/src/helpers/getAttributesFromExtensions.ts b/packages/core/src/helpers/getAttributesFromExtensions.ts index 9136be1c..b7a64b18 100644 --- a/packages/core/src/helpers/getAttributesFromExtensions.ts +++ b/packages/core/src/helpers/getAttributesFromExtensions.ts @@ -20,6 +20,7 @@ export default function getAttributesFromExtensions(extensions: Extensions): Ext rendered: true, renderHTML: null, parseHTML: null, + keepOnSplit: true, } extensions.forEach(extension => { diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index aec14f17..f1f5bcb6 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -60,6 +60,7 @@ export type Attribute = { rendered?: boolean, renderHTML?: ((attributes: { [key: string]: any }) => { [key: string]: any } | null) | null, parseHTML?: ((element: HTMLElement) => { [key: string]: any } | null) | null, + keepOnSplit: boolean, } export type Attributes = { diff --git a/packages/extension-text-align/src/text-align.ts b/packages/extension-text-align/src/text-align.ts index 7d766eba..8984a0b0 100644 --- a/packages/extension-text-align/src/text-align.ts +++ b/packages/extension-text-align/src/text-align.ts @@ -59,14 +59,14 @@ export const TextAlign = Extension.create({ return { // TODO: re-use only 'textAlign' attribute // TODO: use custom splitBlock only for `this.options.types` - Enter: () => this.editor.commands.first(({ commands }) => [ - () => commands.newlineInCode(), - () => commands.createParagraphNear(), - () => commands.liftEmptyBlock(), - () => commands.splitBlock({ - withAttributes: true, - }), - ]), + // Enter: () => this.editor.commands.first(({ commands }) => [ + // () => commands.newlineInCode(), + // () => commands.createParagraphNear(), + // () => commands.liftEmptyBlock(), + // () => commands.splitBlock({ + // withAttributes: true, + // }), + // ]), 'Mod-Shift-l': () => this.editor.commands.setTextAlign('left'), 'Mod-Shift-e': () => this.editor.commands.setTextAlign('center'), 'Mod-Shift-r': () => this.editor.commands.setTextAlign('right'), From 30398717671f79e3884f9fd48da566c1248ab944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Thu, 28 Jan 2021 23:51:20 +0100 Subject: [PATCH 2/8] add keepOnSplit option to splitListItem --- packages/core/src/commands/splitListItem.ts | 118 +++++++++++++++++- packages/extension-task-item/src/task-item.ts | 1 + 2 files changed, 115 insertions(+), 4 deletions(-) diff --git a/packages/core/src/commands/splitListItem.ts b/packages/core/src/commands/splitListItem.ts index c05da4cb..a55e045f 100644 --- a/packages/core/src/commands/splitListItem.ts +++ b/packages/core/src/commands/splitListItem.ts @@ -1,13 +1,123 @@ -import { splitListItem as originalSplitListItem } from 'prosemirror-schema-list' -import { NodeType } from 'prosemirror-model' +import { + NodeType, + Node as ProseMirrorNode, + Fragment, + Slice, +} from 'prosemirror-model' +import { canSplit } from 'prosemirror-transform' import { Command } from '../types' import getNodeType from '../helpers/getNodeType' /** * Splits one list item into two list items. */ -export const splitListItem = (typeOrName: string | NodeType): Command => ({ state, dispatch }) => { +export const splitListItem = (typeOrName: string | NodeType): Command => ({ state, dispatch, editor }) => { const type = getNodeType(typeOrName, state.schema) + const { $from, $to } = state.selection - return originalSplitListItem(type)(state, dispatch) + // @ts-ignore + // eslint-disable-next-line + const node: ProseMirrorNode = state.selection.node + + if ((node && node.isBlock) || $from.depth < 2 || !$from.sameParent($to)) { + return false + } + + const grandParent = $from.node(-1) + + if (grandParent.type !== type) { + return false + } + + if ($from.parent.content.size === 0 && $from.node(-1).childCount === $from.indexAfter(-1)) { + // In an empty block. If this is a nested list, the wrapping + // list item should be split. Otherwise, bail out and let next + // command handle lifting. + if ( + $from.depth === 2 + || $from.node(-3).type !== type + || $from.index(-2) !== $from.node(-2).childCount - 1 + ) { + return false + } + + if (dispatch) { + let wrap = Fragment.empty + const keepItem = $from.index(-1) > 0 + + // Build a fragment containing empty versions of the structure + // from the outer list item to the parent node of the cursor + for (let d = $from.depth - (keepItem ? 1 : 2); d >= $from.depth - 3; d -= 1) { + wrap = Fragment.from($from.node(d).copy(wrap)) + } + + // Add a second list item with an empty default start node + // @ts-ignore + wrap = wrap.append(Fragment.from(type.createAndFill())) + + const tr = state.tr.replace( + $from.before(keepItem ? undefined : -1), + $from.after(-3), + new Slice(wrap, keepItem ? 3 : 2, 2), + ) + + tr + // @ts-ignore + .setSelection(state.selection.constructor.near(tr.doc.resolve($from.pos + (keepItem ? 3 : 2)))) + .scrollIntoView() + } + + return true + } + + const nextType = $to.pos === $from.end() + ? grandParent.contentMatchAt(0).defaultType + : null + + const extensionAttributes = editor.extensionManager.attributes + const currentTypeAttributes = grandParent.attrs + const currentNextTypeAttributes = $from.node().attrs + const newTypeAttributes = Object.fromEntries(Object + .entries(currentTypeAttributes) + .filter(([name]) => { + const extensionAttribute = extensionAttributes.find(item => { + return item.type === grandParent.type.name && item.name === name + }) + + if (!extensionAttribute) { + return false + } + + return extensionAttribute.attribute.keepOnSplit + })) + const newNextTypeAttributes = Object.fromEntries(Object + .entries(currentNextTypeAttributes) + .filter(([name]) => { + const extensionAttribute = extensionAttributes.find(item => { + return item.type === $from.node().type.name && item.name === name + }) + + if (!extensionAttribute) { + return false + } + + return extensionAttribute.attribute.keepOnSplit + })) + + const tr = state.tr.delete($from.pos, $to.pos) + const types = nextType + ? [{ type, attrs: newTypeAttributes }, { type: nextType, attrs: newNextTypeAttributes }] + : [{ type, attrs: newTypeAttributes }] + + // @ts-ignore + if (!canSplit(tr.doc, $from.pos, 2, nextType && [null])) { + return false + } + + if (dispatch) { + // @ts-ignore + tr.split($from.pos, 2, types).scrollIntoView() + } + + return true } diff --git a/packages/extension-task-item/src/task-item.ts b/packages/extension-task-item/src/task-item.ts index d1d1efd0..cfbf2402 100644 --- a/packages/extension-task-item/src/task-item.ts +++ b/packages/extension-task-item/src/task-item.ts @@ -34,6 +34,7 @@ export const TaskItem = Node.create({ renderHTML: attributes => ({ 'data-checked': attributes.checked, }), + keepOnSplit: false, }, } }, From 89deb4c6157b0e41940dceab41361168643ac693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 29 Jan 2021 00:08:01 +0100 Subject: [PATCH 3/8] refactoring --- packages/core/src/commands/splitListItem.ts | 11 ++++------- packages/extension-text-align/src/text-align.ts | 10 ---------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/packages/core/src/commands/splitListItem.ts b/packages/core/src/commands/splitListItem.ts index a55e045f..f017ab26 100644 --- a/packages/core/src/commands/splitListItem.ts +++ b/packages/core/src/commands/splitListItem.ts @@ -5,6 +5,7 @@ import { Slice, } from 'prosemirror-model' import { canSplit } from 'prosemirror-transform' +import { TextSelection } from 'prosemirror-state' import { Command } from '../types' import getNodeType from '../helpers/getNodeType' @@ -52,8 +53,7 @@ export const splitListItem = (typeOrName: string | NodeType): Command => ({ stat } // Add a second list item with an empty default start node - // @ts-ignore - wrap = wrap.append(Fragment.from(type.createAndFill())) + wrap = wrap.append(Fragment.from(type.createAndFill() || undefined)) const tr = state.tr.replace( $from.before(keepItem ? undefined : -1), @@ -62,8 +62,7 @@ export const splitListItem = (typeOrName: string | NodeType): Command => ({ stat ) tr - // @ts-ignore - .setSelection(state.selection.constructor.near(tr.doc.resolve($from.pos + (keepItem ? 3 : 2)))) + .setSelection(TextSelection.near(tr.doc.resolve($from.pos + (keepItem ? 3 : 2)))) .scrollIntoView() } @@ -109,13 +108,11 @@ export const splitListItem = (typeOrName: string | NodeType): Command => ({ stat ? [{ type, attrs: newTypeAttributes }, { type: nextType, attrs: newNextTypeAttributes }] : [{ type, attrs: newTypeAttributes }] - // @ts-ignore - if (!canSplit(tr.doc, $from.pos, 2, nextType && [null])) { + if (!canSplit(tr.doc, $from.pos, 2)) { return false } if (dispatch) { - // @ts-ignore tr.split($from.pos, 2, types).scrollIntoView() } diff --git a/packages/extension-text-align/src/text-align.ts b/packages/extension-text-align/src/text-align.ts index 8984a0b0..66e37a56 100644 --- a/packages/extension-text-align/src/text-align.ts +++ b/packages/extension-text-align/src/text-align.ts @@ -57,16 +57,6 @@ export const TextAlign = Extension.create({ addKeyboardShortcuts() { return { - // TODO: re-use only 'textAlign' attribute - // TODO: use custom splitBlock only for `this.options.types` - // Enter: () => this.editor.commands.first(({ commands }) => [ - // () => commands.newlineInCode(), - // () => commands.createParagraphNear(), - // () => commands.liftEmptyBlock(), - // () => commands.splitBlock({ - // withAttributes: true, - // }), - // ]), 'Mod-Shift-l': () => this.editor.commands.setTextAlign('left'), 'Mod-Shift-e': () => this.editor.commands.setTextAlign('center'), 'Mod-Shift-r': () => this.editor.commands.setTextAlign('right'), From f71a51cbb04955aba522fc8766b418984916a0f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 29 Jan 2021 00:24:31 +0100 Subject: [PATCH 4/8] fix bug --- packages/core/src/commands/splitListItem.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/src/commands/splitListItem.ts b/packages/core/src/commands/splitListItem.ts index f017ab26..d85dbea5 100644 --- a/packages/core/src/commands/splitListItem.ts +++ b/packages/core/src/commands/splitListItem.ts @@ -53,7 +53,8 @@ export const splitListItem = (typeOrName: string | NodeType): Command => ({ stat } // Add a second list item with an empty default start node - wrap = wrap.append(Fragment.from(type.createAndFill() || undefined)) + const nextType = type.contentMatch.defaultType?.createAndFill($from.node().attrs) || undefined + wrap = wrap.append(Fragment.from(type.createAndFill(null, nextType) || undefined)) const tr = state.tr.replace( $from.before(keepItem ? undefined : -1), From 4b4ec7d7660bf481ae1f7f7621f25bf47afb6d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 29 Jan 2021 00:27:58 +0100 Subject: [PATCH 5/8] refactoring --- packages/core/src/commands/splitListItem.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/core/src/commands/splitListItem.ts b/packages/core/src/commands/splitListItem.ts index d85dbea5..006aad24 100644 --- a/packages/core/src/commands/splitListItem.ts +++ b/packages/core/src/commands/splitListItem.ts @@ -12,7 +12,9 @@ import getNodeType from '../helpers/getNodeType' /** * Splits one list item into two list items. */ -export const splitListItem = (typeOrName: string | NodeType): Command => ({ state, dispatch, editor }) => { +export const splitListItem = (typeOrName: string | NodeType): Command => ({ + tr, state, dispatch, editor, +}) => { const type = getNodeType(typeOrName, state.schema) const { $from, $to } = state.selection @@ -56,13 +58,12 @@ export const splitListItem = (typeOrName: string | NodeType): Command => ({ stat const nextType = type.contentMatch.defaultType?.createAndFill($from.node().attrs) || undefined wrap = wrap.append(Fragment.from(type.createAndFill(null, nextType) || undefined)) - const tr = state.tr.replace( - $from.before(keepItem ? undefined : -1), - $from.after(-3), - new Slice(wrap, keepItem ? 3 : 2, 2), - ) - tr + .replace( + $from.before(keepItem ? undefined : -1), + $from.after(-3), + new Slice(wrap, keepItem ? 3 : 2, 2), + ) .setSelection(TextSelection.near(tr.doc.resolve($from.pos + (keepItem ? 3 : 2)))) .scrollIntoView() } @@ -104,7 +105,8 @@ export const splitListItem = (typeOrName: string | NodeType): Command => ({ stat return extensionAttribute.attribute.keepOnSplit })) - const tr = state.tr.delete($from.pos, $to.pos) + tr.delete($from.pos, $to.pos) + const types = nextType ? [{ type, attrs: newTypeAttributes }, { type: nextType, attrs: newNextTypeAttributes }] : [{ type, attrs: newTypeAttributes }] From 72ff2d212e2d7a232d82f83329ce867e45bad740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 29 Jan 2021 08:56:52 +0100 Subject: [PATCH 6/8] improve clearNodes command --- packages/core/src/commands/clearNodes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/commands/clearNodes.ts b/packages/core/src/commands/clearNodes.ts index 219f3c44..1aec3bbb 100644 --- a/packages/core/src/commands/clearNodes.ts +++ b/packages/core/src/commands/clearNodes.ts @@ -18,7 +18,7 @@ export const clearNodes = (): Command => ({ state, tr, dispatch }) => { const targetLiftDepth = liftTarget(nodeRange) if (node.type.isTextblock && dispatch) { - tr.setNodeMarkup(nodeRange.start, state.schema.nodes.paragraph) + tr.setNodeMarkup(nodeRange.start, state.doc.type.contentMatch.defaultType) } if ((targetLiftDepth || targetLiftDepth === 0) && dispatch) { From 97eb9c411cc2f5316b6dcb21b2931980699f0a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 29 Jan 2021 09:33:42 +0100 Subject: [PATCH 7/8] add getSplittedAttributes helper --- packages/core/src/commands/splitBlock.ts | 21 +++----- packages/core/src/commands/splitListItem.ts | 49 +++++++------------ .../core/src/helpers/getSplittedAttributes.ts | 21 ++++++++ 3 files changed, 46 insertions(+), 45 deletions(-) create mode 100644 packages/core/src/helpers/getSplittedAttributes.ts diff --git a/packages/core/src/commands/splitBlock.ts b/packages/core/src/commands/splitBlock.ts index f2236a8e..c84b0e06 100644 --- a/packages/core/src/commands/splitBlock.ts +++ b/packages/core/src/commands/splitBlock.ts @@ -2,6 +2,7 @@ import { canSplit } from 'prosemirror-transform' import { ContentMatch, Fragment } from 'prosemirror-model' import { EditorState, NodeSelection, TextSelection } from 'prosemirror-state' import { Command } from '../types' +import getSplittedAttributes from '../helpers/getSplittedAttributes' function defaultBlockAt(match: ContentMatch) { for (let i = 0; i < match.edgeCount; i + 1) { @@ -42,22 +43,12 @@ export const splitBlock = (options: Partial = {}): Command => const config = { ...defaultOptions, ...options } const { selection, doc } = tr const { $from, $to } = selection - const extensionAttributes = editor.extensionManager.attributes - .filter(item => item.type === $from.node().type.name) - - const currentAttributes = $from.node().attrs - const newAttributes = Object.fromEntries(Object - .entries(currentAttributes) - .filter(([name]) => { - const extensionAttribute = extensionAttributes.find(item => item.name === name) - - if (!extensionAttribute) { - return false - } - - return extensionAttribute.attribute.keepOnSplit - })) + const newAttributes = getSplittedAttributes( + extensionAttributes, + $from.node().type.name, + $from.node().attrs, + ) if (selection instanceof NodeSelection && selection.node.isBlock) { if (!$from.parentOffset || !canSplit(doc, $from.pos)) { diff --git a/packages/core/src/commands/splitListItem.ts b/packages/core/src/commands/splitListItem.ts index 006aad24..aca57dba 100644 --- a/packages/core/src/commands/splitListItem.ts +++ b/packages/core/src/commands/splitListItem.ts @@ -8,6 +8,7 @@ import { canSplit } from 'prosemirror-transform' import { TextSelection } from 'prosemirror-state' import { Command } from '../types' import getNodeType from '../helpers/getNodeType' +import getSplittedAttributes from '../helpers/getSplittedAttributes' /** * Splits one list item into two list items. @@ -32,6 +33,8 @@ export const splitListItem = (typeOrName: string | NodeType): Command => ({ return false } + const extensionAttributes = editor.extensionManager.attributes + if ($from.parent.content.size === 0 && $from.node(-1).childCount === $from.indexAfter(-1)) { // In an empty block. If this is a nested list, the wrapping // list item should be split. Otherwise, bail out and let next @@ -55,7 +58,12 @@ export const splitListItem = (typeOrName: string | NodeType): Command => ({ } // Add a second list item with an empty default start node - const nextType = type.contentMatch.defaultType?.createAndFill($from.node().attrs) || undefined + const newNextTypeAttributes = getSplittedAttributes( + extensionAttributes, + $from.node().type.name, + $from.node().attrs, + ) + const nextType = type.contentMatch.defaultType?.createAndFill(newNextTypeAttributes) || undefined wrap = wrap.append(Fragment.from(type.createAndFill(null, nextType) || undefined)) tr @@ -75,35 +83,16 @@ export const splitListItem = (typeOrName: string | NodeType): Command => ({ ? grandParent.contentMatchAt(0).defaultType : null - const extensionAttributes = editor.extensionManager.attributes - const currentTypeAttributes = grandParent.attrs - const currentNextTypeAttributes = $from.node().attrs - const newTypeAttributes = Object.fromEntries(Object - .entries(currentTypeAttributes) - .filter(([name]) => { - const extensionAttribute = extensionAttributes.find(item => { - return item.type === grandParent.type.name && item.name === name - }) - - if (!extensionAttribute) { - return false - } - - return extensionAttribute.attribute.keepOnSplit - })) - const newNextTypeAttributes = Object.fromEntries(Object - .entries(currentNextTypeAttributes) - .filter(([name]) => { - const extensionAttribute = extensionAttributes.find(item => { - return item.type === $from.node().type.name && item.name === name - }) - - if (!extensionAttribute) { - return false - } - - return extensionAttribute.attribute.keepOnSplit - })) + const newTypeAttributes = getSplittedAttributes( + extensionAttributes, + grandParent.type.name, + grandParent.attrs, + ) + const newNextTypeAttributes = getSplittedAttributes( + extensionAttributes, + $from.node().type.name, + $from.node().attrs, + ) tr.delete($from.pos, $to.pos) diff --git a/packages/core/src/helpers/getSplittedAttributes.ts b/packages/core/src/helpers/getSplittedAttributes.ts new file mode 100644 index 00000000..8d3396ab --- /dev/null +++ b/packages/core/src/helpers/getSplittedAttributes.ts @@ -0,0 +1,21 @@ +import { AnyObject, ExtensionAttribute } from '../types' + +export default function getSplittedAttributes( + extensionAttributes: ExtensionAttribute[], + typeName: string, + attributes: AnyObject, +): AnyObject { + return Object.fromEntries(Object + .entries(attributes) + .filter(([name]) => { + const extensionAttribute = extensionAttributes.find(item => { + return item.type === typeName && item.name === name + }) + + if (!extensionAttribute) { + return false + } + + return extensionAttribute.attribute.keepOnSplit + })) +} From c2cb0e8752d876be389197196f6d13101401b09a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 29 Jan 2021 09:34:53 +0100 Subject: [PATCH 8/8] rename --- packages/core/src/commands/splitBlock.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/src/commands/splitBlock.ts b/packages/core/src/commands/splitBlock.ts index c84b0e06..46d4e883 100644 --- a/packages/core/src/commands/splitBlock.ts +++ b/packages/core/src/commands/splitBlock.ts @@ -16,7 +16,7 @@ function defaultBlockAt(match: ContentMatch) { } export interface SplitBlockOptions { - withMarks: boolean, + keepMarks: boolean, } function keepMarks(state: EditorState) { @@ -38,7 +38,7 @@ export const splitBlock = (options: Partial = {}): Command => editor, }) => { const defaultOptions: SplitBlockOptions = { - withMarks: true, + keepMarks: true, } const config = { ...defaultOptions, ...options } const { selection, doc } = tr @@ -56,7 +56,7 @@ export const splitBlock = (options: Partial = {}): Command => } if (dispatch) { - if (config.withMarks) { + if (config.keepMarks) { keepMarks(state) } @@ -117,7 +117,7 @@ export const splitBlock = (options: Partial = {}): Command => } } - if (config.withMarks) { + if (config.keepMarks) { keepMarks(state) }