From 468b670bcce6e52db36067c3c9ebc9fba84c2afc Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sat, 6 Sep 2025 22:33:31 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/8019 --- app/src/protyle/wysiwyg/index.ts | 1 - app/src/protyle/wysiwyg/remove.ts | 46 ++++++++++++-------------- app/src/protyle/wysiwyg/transaction.ts | 3 ++ 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index e9032cf70..8723b81da 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -1798,7 +1798,6 @@ export class WYSIWYG { needClipboardWrite = true; const response = await fetchSyncPost("/api/block/getHeadingChildrenDOM", {id: item.getAttribute("data-node-id")}); html += response.data; - setFold(protyle, topElement, undefined, true); } else { html += removeEmbed(topElement); } diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.ts index 61501fd70..c4a91db52 100644 --- a/app/src/protyle/wysiwyg/remove.ts +++ b/app/src/protyle/wysiwyg/remove.ts @@ -23,6 +23,7 @@ import {hasClosestByClassName} from "../util/hasClosest"; import {getInstanceById} from "../../layout/util"; import {Tab} from "../../layout/Tab"; import {Backlink} from "../../layout/dock/Backlink"; +import {fetchSyncPost} from "../../util/fetch"; export const removeBlock = async (protyle: IProtyle, blockElement: Element, range: Range, type: "Delete" | "Backspace" | "remove") => { protyle.observerLoad?.disconnect(); @@ -32,7 +33,7 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang if (selectElements?.length > 0) { const deletes: IOperation[] = []; const inserts: IOperation[] = []; - let sideElement; + let sideElement: Element | boolean; let sideIsNext = false; if (type === "Backspace") { sideElement = selectElements[0].previousElementSibling; @@ -52,7 +53,8 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang let topParentElement: Element; hideElements(["select"], protyle); let foldPreviousId: string; - selectElements.find((item: HTMLElement) => { + for (let i = 0; i < selectElements.length; i++) { + const item = selectElements[i]; const topElement = getTopAloneElement(item); topParentElement = topElement.parentElement; const id = topElement.getAttribute("data-node-id"); @@ -79,19 +81,23 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang sideIsNext = false; } if (topElement.getAttribute("data-type") === "NodeHeading" && topElement.getAttribute("fold") === "1") { - // https://github.com/siyuan-note/siyuan/issues/2188 - setFold(protyle, topElement, undefined, true); + const foldTransaction = await fetchSyncPost("/api/block/getHeadingDeleteTransaction", { + id: topElement.getAttribute("data-node-id"), + }); + deletes.push(...foldTransaction.data.doOperations.slice(1)); let previousID = topElement.previousElementSibling ? topElement.previousElementSibling.getAttribute("data-node-id") : ""; if (typeof foldPreviousId !== "undefined") { previousID = foldPreviousId; } - inserts.push({ - action: "insert", - data: topElement.outerHTML, - id, - previousID: previousID, - parentID: topElement.parentElement.getAttribute("data-node-id") || protyle.block.parentID + foldTransaction.data.undoOperations.forEach((operationItem: IOperation, index: number) => { + operationItem.previousID = previousID; + if (index > 0) { + operationItem.context = { + ignoreProcess: "true" + }; + } }); + inserts.push(...foldTransaction.data.undoOperations); // 折叠块和非折叠块同时删除时撤销异常 https://github.com/siyuan-note/siyuan/issues/11312 let foldPreviousElement = getPreviousBlock(topElement); while (foldPreviousElement && foldPreviousElement.childElementCount === 3) { @@ -102,17 +108,9 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang } else { foldPreviousId = ""; } - // https://github.com/siyuan-note/siyuan/issues/4422 + // // https://github.com/siyuan-note/siyuan/issues/4422 topElement.firstElementChild.removeAttribute("contenteditable"); - // 在折叠标题后输入文字,然后全选删除再撤销会重建索引。因此不能删除折叠标题后新输入的输入折叠标题下的内容 - const nextElement = topElement.nextElementSibling; - if (nextElement) { - const nextType = nextElement.getAttribute("data-type"); - if (nextType !== "NodeHeading" || - (nextType === "NodeHeading" && nextElement.getAttribute("data-subtype") > topElement.getAttribute("data-subtype"))) { - return true; - } - } + topElement.remove(); } else { let data = topElement.outerHTML; // 不能 spin ,否则 li 会变为 list if (topElement.classList.contains("render-node") || topElement.querySelector("div.render-node")) { @@ -136,7 +134,7 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang } topElement.remove(); } - }); + } if (sideElement) { if (protyle.block.showAll && sideElement.classList.contains("protyle-wysiwyg") && protyle.wysiwyg.element.childElementCount === 0) { setTimeout(() => { @@ -164,11 +162,11 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang // https://github.com/siyuan-note/siyuan/issues/10389 // https://github.com/siyuan-note/siyuan/issues/10899 if (type !== "Backspace" && sideIsNext) { - focusBlock(sideElement); + focusBlock(sideElement as Element); } else { - focusBlock(sideElement, undefined, false); + focusBlock(sideElement as Element, undefined, false); } - scrollCenter(protyle, sideElement); + scrollCenter(protyle, sideElement as Element); if (listElement) { inserts.push({ action: "update", diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts index 94f2014c1..3ca640a08 100644 --- a/app/src/protyle/wysiwyg/transaction.ts +++ b/app/src/protyle/wysiwyg/transaction.ts @@ -754,6 +754,9 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo: return; } if (operation.action === "insert") { + if (operation.context?.ignoreProcess === "true") { + return; + } const cursorElements = []; if (operation.previousID) { const previousElement = protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.previousID}"]`);