Vanessa 2025-11-17 21:35:15 +08:00
parent 72ed9c37f8
commit f293fa5d26
3 changed files with 18 additions and 20 deletions

View file

@ -617,7 +617,7 @@ export const updateOutline = (models: IModels, protyle: IProtyle, reload = false
item.isPreview = !protyle.preview.element.classList.contains("fn__none");
item.update(response, blockId);
if (protyle) {
item.updateDocTitle(protyle.background.ial, response.data?.length);
item.updateDocTitle(protyle.background.ial, response.data?.length || 0);
if (getSelection().rangeCount > 0) {
const startContainer = getSelection().getRangeAt(0).startContainer;
if (protyle.wysiwyg.element.contains(startContainer)) {

View file

@ -70,7 +70,7 @@ export class Outline extends Model {
this.updateDocTitle({
title: data.data.title,
icon: Constants.ZWSP
});
}, -1);
}
break;
case "unmount":
@ -331,6 +331,7 @@ export class Outline extends Model {
preview: this.isPreview
}, response => {
this.update(response);
this.updateDocTitle((options.tab.model as Editor)?.editor.protyle?.background?.ial, response.data?.length || 0);
});
}
@ -478,32 +479,32 @@ export class Outline extends Model {
public updateDocTitle(ial?: IObject, count?: number) {
const docTitleElement = this.headerElement.nextElementSibling as HTMLElement;
if (this.type === "pin") {
if (!ial && typeof count === "undefined") {
docTitleElement.classList.add("fn__none");
return;
}
if (ial) {
let iconHTML = `${unicode2Emoji(ial.icon || window.siyuan.storage[Constants.LOCAL_IMAGES].file, "b3-list-item__graphic", true)}`;
if (ial.icon === Constants.ZWSP && docTitleElement.firstElementChild) {
iconHTML = docTitleElement.firstElementChild.outerHTML;
}
docTitleElement.innerHTML = `${iconHTML}<span class="b3-list-item__text">${escapeHtml(ial.title)}</span>`;
docTitleElement.innerHTML = `${iconHTML}<span class="b3-list-item__text">${escapeHtml(ial.title)}</span>${docTitleElement.querySelector(".counter")?.outerHTML || ""}`;
docTitleElement.setAttribute("title", ial.title);
docTitleElement.classList.remove("fn__none");
} else if (count === undefined) {
docTitleElement.classList.add("fn__none");
}
if (count !== undefined && docTitleElement) {
const textElement = docTitleElement.querySelector(".b3-list-item__text");
if (textElement) {
// count 为 -1 时,不对数量进行更新
if (typeof count === "number" && count !== -1) {
const counterElement = docTitleElement.querySelector(".counter") as HTMLElement;
if (count > 0) {
if (counterElement) {
counterElement.textContent = count.toString();
} else {
textElement.insertAdjacentHTML("afterend", `<span class="counter">${count.toString()}</span>`);
docTitleElement.insertAdjacentHTML("beforeend", `<span class="counter">${count.toString()}</span>`);
}
} else {
counterElement?.remove();
}
}
}
} else {
docTitleElement.classList.add("fn__none");
}
@ -546,6 +547,7 @@ export class Outline extends Model {
return;
}
this.update(response);
this.updateDocTitle(null, response.data?.length || 0);
// https://github.com/siyuan-note/siyuan/issues/8372
if (getSelection().rangeCount > 0) {
const blockElement = hasClosestBlock(getSelection().getRangeAt(0).startContainer);
@ -643,7 +645,6 @@ export class Outline extends Model {
this.blockId = callbackId;
}
this.tree.updateData(data.data);
this.updateDocTitle(undefined, data.data?.length);
if (this.isPreview) {
this.tree.element.querySelectorAll(".popover__block").forEach(item => {

View file

@ -613,9 +613,6 @@ export class Dock {
blockId: editor?.protyle?.block?.rootID,
isPreview: editor?.protyle?.preview ? !editor.protyle.preview.element.classList.contains("fn__none") : false
});
if (editor?.protyle?.title?.editElement) {
outline.updateDocTitle(editor.protyle?.background?.ial);
}
tab.addModel(outline);
}
});