mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-08-06 13:38:49 +08:00
Merge branch 'main' of github.com:ueberdosis/tiptap-next into main
This commit is contained in:
commit
7c46c83c5d
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user