fix: set cursor position in setHorizontalRule correctly, fix #2429
This commit is contained in:
@@ -49,15 +49,14 @@ export const HorizontalRule = Node.create<HorizontalRuleOptions>({
|
||||
// set cursor after horizontal rule
|
||||
.command(({ tr, dispatch }) => {
|
||||
if (dispatch) {
|
||||
const { parent, pos } = tr.selection.$from
|
||||
const posAfter = pos + 1
|
||||
const nodeAfter = tr.doc.nodeAt(posAfter)
|
||||
const { $to } = tr.selection
|
||||
const posAfter = $to.end()
|
||||
|
||||
if (nodeAfter) {
|
||||
tr.setSelection(TextSelection.create(tr.doc, posAfter))
|
||||
if ($to.nodeAfter) {
|
||||
tr.setSelection(TextSelection.create(tr.doc, $to.pos))
|
||||
} else {
|
||||
// add node after horizontal rule if it’s the end of the document
|
||||
const node = parent.type.contentMatch.defaultType?.create()
|
||||
const node = $to.parent.type.contentMatch.defaultType?.create()
|
||||
|
||||
if (node) {
|
||||
tr.insert(posAfter, node)
|
||||
|
||||
Reference in New Issue
Block a user