Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add defaultType option to horizontal-rule #5877

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/extension-horizontal-rule/src/horizontal-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ export interface HorizontalRuleOptions {
* @default {}
* @example { class: 'foo' }
*/
HTMLAttributes: Record<string, any>
HTMLAttributes: Record<string, any>,
/**
* The default type to insert after the horizontal rule.
* @default "paragraph"
* @example "heading"
*/
defaultType: string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the change, but I feel like defaultType could be more descriptive.

Maybe something like:

  • insertAfter
  • afterType

}

declare module '@tiptap/core' {
Expand All @@ -34,6 +40,7 @@ export const HorizontalRule = Node.create<HorizontalRuleOptions>({
addOptions() {
return {
HTMLAttributes: {},
defaultType: "paragraph",
}
},

Expand Down Expand Up @@ -77,7 +84,7 @@ export const HorizontalRule = Node.create<HorizontalRuleOptions>({
return (
currentChain
// set cursor after horizontal rule
.command(({ tr, dispatch }) => {
.command(({ state, tr, dispatch }) => {
if (dispatch) {
const { $to } = tr.selection
const posAfter = $to.end()
Expand All @@ -92,7 +99,7 @@ export const HorizontalRule = Node.create<HorizontalRuleOptions>({
}
} 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)
Expand Down