Merge branch 'main' of github.com:ueberdosis/tiptap-next into main

This commit is contained in:
Hans Pagel 2021-04-06 23:58:13 +02:00
commit 7c46c83c5d
2 changed files with 21 additions and 2 deletions

View File

@ -22,7 +22,9 @@
"dist"
],
"peerDependencies": {
"@tiptap/core": "^2.0.0-beta.1",
"prosemirror-commands": "^1.1.3"
"@tiptap/core": "^2.0.0-beta.1"
},
"dependencies": {
"prosemirror-state": "^1.3.4"
}
}

View File

@ -4,6 +4,7 @@ import {
nodeInputRule,
mergeAttributes,
} from '@tiptap/core'
import { TextSelection } from 'prosemirror-state'
export interface HorizontalRuleOptions {
HTMLAttributes: {
@ -46,6 +47,22 @@ export const HorizontalRule = Node.create<HorizontalRuleOptions>({
setHorizontalRule: () => ({ tr, dispatch }) => {
if (dispatch) {
tr.replaceSelectionWith(this.type.create())
const { parent, pos } = tr.selection.$from
const posAfter = pos + 1
const nodeAfter = tr.doc.nodeAt(posAfter)
// end of document
if (!nodeAfter) {
const node = parent.type.contentMatch.defaultType?.create()
if (node) {
tr.insert(posAfter, node)
tr.setSelection(TextSelection.create(tr.doc, posAfter))
}
}
tr.scrollIntoView()
}
return true