From 89418f95d4e171752c9dff96bcadaaeffccf52b3 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 26 Oct 2022 23:32:46 +0800 Subject: [PATCH] :bug: fix https://github.com/siyuan-note/siyuan/issues/6359 --- app/src/block/util.ts | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/app/src/block/util.ts b/app/src/block/util.ts index b9ee773ef..8a105154b 100644 --- a/app/src/block/util.ts +++ b/app/src/block/util.ts @@ -63,7 +63,7 @@ export const genSBElement = (layout: string, id?: string, attrHTML?: string) => return sbElement; }; -export const jumpToParentNext = (protyle:IProtyle,nodeElement: Element) => { +export const jumpToParentNext = (protyle: IProtyle, nodeElement: Element) => { const topElement = getTopAloneElement(nodeElement); if (topElement) { const topParentElement = hasClosestByClassName(topElement, "list") || hasClosestByClassName(topElement, "bq") || hasClosestByClassName(topElement, "sb") || topElement; @@ -97,14 +97,6 @@ export const insertEmptyBlock = (protyle: IProtyle, position: InsertPosition, id if (!blockElement) { return; } - let previousID; - if (position === "beforebegin") { - if (blockElement.previousElementSibling) { - previousID = blockElement.previousElementSibling.getAttribute("data-node-id"); - } - } else { - previousID = blockElement.getAttribute("data-node-id"); - } let newElement = genEmptyElement(false, true); let orderIndex = 1; if (blockElement.getAttribute("data-type") === "NodeListItem") { @@ -119,13 +111,23 @@ export const insertEmptyBlock = (protyle: IProtyle, position: InsertPosition, id updateListOrder(newElement.parentElement, orderIndex); updateTransaction(protyle, newElement.parentElement.getAttribute("data-node-id"), newElement.parentElement.outerHTML, parentOldHTML); } else { - transaction(protyle, [{ - action: "insert", - data: newElement.outerHTML, - id: newId, - previousID, - parentID: blockElement.parentElement.getAttribute("data-node-id") || protyle.block.parentID - }], [{ + let doOperations: IOperation[] + if (position === "beforebegin") { + doOperations = [{ + action: "insert", + data: newElement.outerHTML, + id: newId, + nextID: blockElement.getAttribute("data-node-id"), + }]; + } else { + doOperations = [{ + action: "insert", + data: newElement.outerHTML, + id: newId, + previousID: blockElement.getAttribute("data-node-id"), + }]; + } + transaction(protyle, doOperations, [{ action: "delete", id: newId, }]);