From 92768541bbf22dcd9a22c21b2a0d191c95882a09 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sat, 17 Sep 2022 11:28:09 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/5866 --- app/src/protyle/wysiwyg/transaction.ts | 38 ++++++++++++++++++-------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts index 8629ba180..2ad717f4e 100644 --- a/app/src/protyle/wysiwyg/transaction.ts +++ b/app/src/protyle/wysiwyg/transaction.ts @@ -304,24 +304,38 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b return; } if (operation.action === "updateAttrs") { // 调用接口才推送 + let nodeAttrHTML = ""; + const data = operation.data as any; + const attrsResult: IObject = {}; + Object.keys(data.new).forEach(key => { + attrsResult[key] = data.new[key]; + const escapeHTML = data.new[key]; + if (key === "bookmark") { + nodeAttrHTML += `
${escapeHTML}
`; + } else if (key === "name") { + nodeAttrHTML += `
${escapeHTML}
`; + } else if (key === "alias") { + nodeAttrHTML += `
${escapeHTML}
`; + } else if (key === "memo") { + nodeAttrHTML += `
`; + } + }); + if (protyle.block.rootID === operation.id) { + // 文档 + const refElement = protyle.title.element.querySelector(".protyle-attr--refcount"); + if (refElement) { + nodeAttrHTML += refElement.outerHTML; + } + protyle.title.element.querySelector(".protyle-attr").innerHTML = nodeAttrHTML; + protyle.wysiwyg.renderCustom(attrsResult); + return; + } protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach(item => { - const data = operation.data as any; Object.keys(data.old).forEach(key => { item.removeAttribute(key); }); - let nodeAttrHTML = ""; Object.keys(data.new).forEach(key => { item.setAttribute(key, data.new[key]); - const escapeHTML = data.new[key]; - if (key === "bookmark") { - nodeAttrHTML += `
${escapeHTML}
`; - } else if (key === "name") { - nodeAttrHTML += `
${escapeHTML}
`; - } else if (key === "alias") { - nodeAttrHTML += `
${escapeHTML}
`; - } else if (key === "memo") { - nodeAttrHTML += `
`; - } }); const refElement = item.lastElementChild.querySelector(".protyle-attr--refcount"); if (refElement) {