From a47491b9fa68ebe215f79dda962c4a63c4554dbe Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sat, 11 Apr 2026 22:39:24 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/17437 --- app/src/dialog/processSystem.ts | 2 +- app/src/protyle/wysiwyg/transaction.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.ts index 2d66470c3..9d18f61df 100644 --- a/app/src/dialog/processSystem.ts +++ b/app/src/dialog/processSystem.ts @@ -190,7 +190,7 @@ export const setDefRefCount = (data: { // 不能对比 rootId,否则嵌入块中的锚文本无法更新 editor.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${data.blockID}"]`).forEach(item => { // 不能直接查询,否则列表中会获取到第一个列表项的 attr https://github.com/siyuan-note/siyuan/issues/12738 - const countElement = item.lastElementChild.querySelector(".protyle-attr--refcount"); + const countElement = item.lastElementChild?.querySelector(".protyle-attr--refcount"); if (countElement) { if (data.refCount === 0) { countElement.remove(); diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts index f71da0bce..1a5f759f3 100644 --- a/app/src/protyle/wysiwyg/transaction.ts +++ b/app/src/protyle/wysiwyg/transaction.ts @@ -382,9 +382,9 @@ const updateBlock = (updateElements: Element[], protyle: IProtyle, operation: IO // 用于推送和撤销 export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo: boolean) => { - if (protyle.wysiwyg.element.firstElementChild?.classList.contains("protyle-password")) { - return; - } + if (protyle.wysiwyg.element.firstElementChild?.classList.contains("protyle-password")) { + return; + } const updateElements: Element[] = []; Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`)).forEach(item => { if (!isInEmbedBlock(item)) { @@ -688,11 +688,17 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo: if (updateElements.length === 0) { const tempEl = document.createElement("div"); tempEl.setAttribute("data-node-id", operation.id); + tempEl.setAttribute("data-protyle-id", protyle.element.getAttribute("data-id")); updateElements.push(tempEl); fetchPost("/api/block/getBlockDOM", { id: operation.id, }, (response) => { - document.querySelector(`.protyle-wysiwyg [data-node-id="${operation.id}"]`).outerHTML = response.data.dom; + document.querySelectorAll(`.protyle-wysiwyg [data-node-id="${response.data.id}"]`).forEach(item => { + if (item.getAttribute("data-protyle-id")) { + item.outerHTML = response.data.dom; + item.removeAttribute("data-protyle-id"); + } + }); }); } let range;