Переглянути джерело

:bug: fix https://github.com/siyuan-note/siyuan/issues/6359

Vanessa 2 роки тому
батько
коміт
89418f95d4
1 змінених файлів з 18 додано та 16 видалено
  1. 18 16
      app/src/block/util.ts

+ 18 - 16
app/src/block/util.ts

@@ -63,7 +63,7 @@ export const genSBElement = (layout: string, id?: string, attrHTML?: string) =>
     return sbElement;
     return sbElement;
 };
 };
 
 
-export const jumpToParentNext = (protyle:IProtyle,nodeElement: Element) => {
+export const jumpToParentNext = (protyle: IProtyle, nodeElement: Element) => {
     const topElement = getTopAloneElement(nodeElement);
     const topElement = getTopAloneElement(nodeElement);
     if (topElement) {
     if (topElement) {
         const topParentElement = hasClosestByClassName(topElement, "list") || hasClosestByClassName(topElement, "bq") || hasClosestByClassName(topElement, "sb") || 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) {
     if (!blockElement) {
         return;
         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 newElement = genEmptyElement(false, true);
     let orderIndex = 1;
     let orderIndex = 1;
     if (blockElement.getAttribute("data-type") === "NodeListItem") {
     if (blockElement.getAttribute("data-type") === "NodeListItem") {
@@ -119,13 +111,23 @@ export const insertEmptyBlock = (protyle: IProtyle, position: InsertPosition, id
         updateListOrder(newElement.parentElement, orderIndex);
         updateListOrder(newElement.parentElement, orderIndex);
         updateTransaction(protyle, newElement.parentElement.getAttribute("data-node-id"), newElement.parentElement.outerHTML, parentOldHTML);
         updateTransaction(protyle, newElement.parentElement.getAttribute("data-node-id"), newElement.parentElement.outerHTML, parentOldHTML);
     } else {
     } 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",
             action: "delete",
             id: newId,
             id: newId,
         }]);
         }]);