From db46f8a1c2d64bb970468082e909ec79c05079c8 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 9 Oct 2024 00:16:03 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/12703 --- app/src/protyle/wysiwyg/transaction.ts | 27 +++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts index c590e93f3..a574a4a08 100644 --- a/app/src/protyle/wysiwyg/transaction.ts +++ b/app/src/protyle/wysiwyg/transaction.ts @@ -347,14 +347,21 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo: if (operation.action === "unfoldHeading") { const scrollTop = protyle.contentElement.scrollTop; protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach(item => { - if (isInEmbedBlock(item)) { + item.removeAttribute("fold"); + // undo 会走 transaction + if (isUndo) { + return; + } + const embedElement = isInEmbedBlock(item) + if (embedElement) { + embedElement.removeAttribute("data-render"); + blockRender(protyle, embedElement); return; } if (operation.retData) { // undo 的时候没有 retData removeUnfoldRepeatBlock(operation.retData, protyle); item.insertAdjacentHTML("afterend", operation.retData); } - item.removeAttribute("fold"); if (operation.data === "remove") { item.remove(); } @@ -379,6 +386,10 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo: removeFoldHeading(item); } }); + // undo 会走 transaction + if (isUndo) { + return; + } if (operation.retData) { operation.retData.forEach((item: string) => { protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${item}"]`).forEach(item => { @@ -1181,7 +1192,10 @@ const processFold = (operation: IOperation, protyle: IProtyle) => { if (operation.action === "unfoldHeading") { const scrollTop = protyle.contentElement.scrollTop; protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach(item => { - if (isInEmbedBlock(item)) { + const embedElement = isInEmbedBlock(item) + if (embedElement) { + embedElement.removeAttribute("data-render"); + blockRender(protyle, embedElement); return; } if (!item.lastElementChild.classList.contains("protyle-attr")) { @@ -1209,6 +1223,13 @@ const processFold = (operation: IOperation, protyle: IProtyle) => { protyle.scroll.lastScrollTop = scrollTop; return; } + protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach(item => { + const embedElement = isInEmbedBlock(item) + if (embedElement) { + embedElement.removeAttribute("data-render"); + blockRender(protyle, embedElement); + } + }); // 折叠标题后未触发动态加载 https://github.com/siyuan-note/siyuan/issues/4168 if (protyle.wysiwyg.element.lastElementChild.getAttribute("data-eof") !== "2" && !protyle.scroll.element.classList.contains("fn__none") &&