Vanessa 2024-10-09 11:04:18 +08:00
parent db46f8a1c2
commit 017d4f0bf4

View file

@ -171,9 +171,9 @@ export const setDefRefCount = (data: {
"rootID": string "rootID": string
refIDs: string[] refIDs: string[]
}) => { }) => {
getAllEditor().forEach(item => { getAllEditor().forEach(editor => {
if (data.rootID === data.blockID && item.protyle.block.rootID === data.rootID) { if (data.rootID === data.blockID && editor.protyle.block.rootID === data.rootID) {
const attrElement = item.protyle.title.element.querySelector(".protyle-attr"); const attrElement = editor.protyle.title.element.querySelector(".protyle-attr");
const countElement = attrElement.querySelector(".protyle-attr--refcount"); const countElement = attrElement.querySelector(".protyle-attr--refcount");
if (countElement) { if (countElement) {
if (data.refCount === 0) { if (data.refCount === 0) {
@ -188,8 +188,9 @@ export const setDefRefCount = (data: {
return; return;
} }
// 不能对比 rootId否则嵌入块中的锚文本无法更新 // 不能对比 rootId否则嵌入块中的锚文本无法更新
item.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${data.blockID}"]`).forEach(item => { editor.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${data.blockID}"]`).forEach(item => {
const countElement = item.querySelector(".protyle-attr--refcount"); // 不能直接查询,否则列表中会获取到第一个列表项的 attr https://github.com/siyuan-note/siyuan/issues/12738
const countElement = item.lastElementChild.querySelector(".protyle-attr--refcount");
if (countElement) { if (countElement) {
if (data.refCount === 0) { if (data.refCount === 0) {
countElement.remove(); countElement.remove();
@ -197,7 +198,7 @@ export const setDefRefCount = (data: {
countElement.textContent = data.refCount.toString(); countElement.textContent = data.refCount.toString();
} }
} else if (data.refCount > 0) { } else if (data.refCount > 0) {
const attrElement = item.querySelector(".protyle-attr"); const attrElement = item.lastElementChild;
if (attrElement.childElementCount > 0) { if (attrElement.childElementCount > 0) {
attrElement.lastElementChild.insertAdjacentHTML("afterend", `<div class="protyle-attr--refcount popover__block">${data.refCount}</div>`); attrElement.lastElementChild.insertAdjacentHTML("afterend", `<div class="protyle-attr--refcount popover__block">${data.refCount}</div>`);
} else { } else {