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
|
// 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 it’s the end of the document
|
// 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) {
|
if (node) {
|
||||||
tr.insert(posAfter, node)
|
tr.insert(posAfter, node)
|
||||||
|
|||||||
Reference in New Issue
Block a user