From 51f7b80bc5dab1c01f3325d64ef8b5fc484d6204 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 6 Sep 2024 22:48:50 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/8234 --- app/src/dialog/processSystem.ts | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.ts index 9247e5c38..503f57941 100644 --- a/app/src/dialog/processSystem.ts +++ b/app/src/dialog/processSystem.ts @@ -153,25 +153,37 @@ export const setRefDynamicText = (data: { }) => { getAllEditor().forEach(item => { // 不能对比 rootId,否则潜入块中的锚文本无法更新 - const refElement = item.protyle.wysiwyg.element.querySelector(`[data-node-id="${data.blockID}"] span[data-type="block-ref"][data-subtype="d"][data-id="${data.defBlockID}"]`); - if (refElement) { - refElement.innerHTML = data.refText; - } + item.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${data.blockID}"] span[data-type="block-ref"][data-subtype="d"][data-id="${data.defBlockID}"]`).forEach(item => { + item.innerHTML = data.refText; + }); }) } export const setDefRefCount = (data: { "blockID": string, - "defBlockID": string, - "refText": string, + "refCount": number, + "rootRefCount": number, "rootID": string }) => { getAllEditor().forEach(item => { // 不能对比 rootId,否则潜入块中的锚文本无法更新 - const refElement = item.protyle.wysiwyg.element.querySelector(`[data-node-id="${data.blockID}"] span[data-type="block-ref"][data-subtype="d"][data-id="${data.defBlockID}"]`); - if (refElement) { - refElement.innerHTML = data.refText; - } + item.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${data.blockID}"]`).forEach(item => { + const countElement = item.querySelector('.protyle-attr--refcount') + if (countElement) { + if (data.refCount === 0) { + countElement.remove() + } else { + countElement.textContent = data.refCount.toString(); + } + } else if (data.refCount > 0) { + const attrElement = item.querySelector('.protyle-attr') + if (attrElement.childElementCount > 0) { + attrElement.lastElementChild.insertAdjacentHTML("afterend", `
${data.refCount}
`) + } else { + attrElement.innerHTML = `
${data.refCount}
${Constants.ZWSP}` + } + } + }); }) }