浏览代码

:art: fix https://github.com/siyuan-note/siyuan/issues/10592

Vanessa 1 年之前
父节点
当前提交
20e6445f86
共有 2 个文件被更改,包括 14 次插入13 次删除
  1. 11 11
      app/src/protyle/wysiwyg/remove.ts
  2. 3 2
      app/src/protyle/wysiwyg/transaction.ts

+ 11 - 11
app/src/protyle/wysiwyg/remove.ts

@@ -351,14 +351,6 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran
         }
         return;
     }
-    if (blockElement.getAttribute("data-type") === "NodeHeading") {
-        turnsIntoTransaction({
-            protyle: protyle,
-            selectsElement: [blockElement],
-            type: "Blocks2Ps",
-        });
-        return;
-    }
     if (!blockElement.previousElementSibling && blockElement.parentElement.getAttribute("data-type") === "NodeBlockquote") {
         range.insertNode(document.createElement("wbr"));
         const blockParentElement = blockElement.parentElement;
@@ -404,7 +396,15 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran
         removeLi(protyle, blockElement, range, type === "Delete");
         return;
     }
-
+    if (blockElement.getAttribute("data-type") === "NodeHeading") {
+        turnsIntoTransaction({
+            protyle: protyle,
+            selectsElement: [blockElement],
+            type: "Blocks2Ps",
+            range: moveToPrevious(blockElement, range, type === "Delete")
+        });
+        return;
+    }
     if (blockElement.previousElementSibling && blockElement.previousElementSibling.classList.contains("protyle-breadcrumb__bar")) {
         return;
     }
@@ -558,14 +558,14 @@ export const moveToPrevious = (blockElement: Element, range: Range, isDelete: bo
         if (previousBlockElement) {
             const previousEditElement = getContenteditableElement(getLastBlock(previousBlockElement));
             if (previousEditElement) {
-                setLastNodeRange(previousEditElement, range, false);
+                return setLastNodeRange(previousEditElement, range, false);
             }
         }
     }
 };
 
 // https://github.com/siyuan-note/siyuan/issues/10393
-export const removeImage = (imgSelectElement: Element, nodeElement:HTMLElement, range:Range, protyle:IProtyle) => {
+export const removeImage = (imgSelectElement: Element, nodeElement: HTMLElement, range: Range, protyle: IProtyle) => {
     const oldHTML = nodeElement.outerHTML;
     const imgPreviousSibling = hasPreviousSibling(imgSelectElement);
     if (imgPreviousSibling && imgPreviousSibling.textContent.endsWith(Constants.ZWSP)) {

+ 3 - 2
app/src/protyle/wysiwyg/transaction.ts

@@ -856,6 +856,7 @@ export const turnsIntoTransaction = (options: {
     type: TTurnInto,
     level?: number,
     isContinue?: boolean,
+    range?: Range
 }) => {
     let selectsElement: Element[] = options.selectsElement;
     let range: Range;
@@ -977,8 +978,8 @@ export const turnsIntoTransaction = (options: {
     highlightRender(options.protyle.wysiwyg.element);
     avRender(options.protyle.wysiwyg.element, options.protyle);
     blockRender(options.protyle, options.protyle.wysiwyg.element);
-    if (range) {
-        focusByWbr(options.protyle.wysiwyg.element, range);
+    if (range || options.range) {
+        focusByWbr(options.protyle.wysiwyg.element, range || options.range);
     } else {
         focusBlock(options.protyle.wysiwyg.element.querySelector(`[data-node-id="${selectsElement[0].getAttribute("data-node-id")}"]`));
     }