From 0f7169d8c5a666f054c312c780234ffaed629809 Mon Sep 17 00:00:00 2001 From: xiaohui Date: Wed, 27 Nov 2024 12:23:43 +0800 Subject: [PATCH] add defaultType option to horizontal-rule --- .../src/horizontal-rule.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/extension-horizontal-rule/src/horizontal-rule.ts b/packages/extension-horizontal-rule/src/horizontal-rule.ts index ae1d563863b..70b54bdb1ab 100644 --- a/packages/extension-horizontal-rule/src/horizontal-rule.ts +++ b/packages/extension-horizontal-rule/src/horizontal-rule.ts @@ -9,7 +9,13 @@ export interface HorizontalRuleOptions { * @default {} * @example { class: 'foo' } */ - HTMLAttributes: Record + HTMLAttributes: Record, + /** + * The default type to insert after the horizontal rule. + * @default "paragraph" + * @example "heading" + */ + defaultType: string, } declare module '@tiptap/core' { @@ -34,6 +40,7 @@ export const HorizontalRule = Node.create({ addOptions() { return { HTMLAttributes: {}, + defaultType: "paragraph", } }, @@ -77,7 +84,7 @@ export const HorizontalRule = Node.create({ return ( currentChain // set cursor after horizontal rule - .command(({ tr, dispatch }) => { + .command(({ state, tr, dispatch }) => { if (dispatch) { const { $to } = tr.selection const posAfter = $to.end() @@ -92,7 +99,7 @@ export const HorizontalRule = Node.create({ } } else { // add node after horizontal rule if it’s the end of the document - const node = $to.parent.type.contentMatch.defaultType?.create() + const node = state.schema.nodes[this.options.defaultType].create() if (node) { tr.insert(posAfter, node)