fix: set cursor position in setHorizontalRule correctly, fix #2429

This commit is contained in:
Philipp Kühn
2022-01-24 22:49:29 +01:00
parent 75336740c0
commit 34d8011470

View File

@@ -49,15 +49,14 @@ export const HorizontalRule = Node.create<HorizontalRuleOptions>({
// set cursor after horizontal rule // set cursor after horizontal rule
.command(({ tr, dispatch }) => { .command(({ tr, dispatch }) => {
if (dispatch) { if (dispatch) {
const { parent, pos } = tr.selection.$from const { $to } = tr.selection
const posAfter = pos + 1 const posAfter = $to.end()
const nodeAfter = tr.doc.nodeAt(posAfter)
if (nodeAfter) { if ($to.nodeAfter) {
tr.setSelection(TextSelection.create(tr.doc, posAfter)) tr.setSelection(TextSelection.create(tr.doc, $to.pos))
} else { } else {
// add node after horizontal rule if its the end of the document // add node after horizontal rule if its the end of the document
const node = parent.type.contentMatch.defaultType?.create() const node = $to.parent.type.contentMatch.defaultType?.create()
if (node) { if (node) {
tr.insert(posAfter, node) tr.insert(posAfter, node)