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
.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 its 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)