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.isPreview = !protyle.preview.element.classList.contains("fn__none");
item.update(response, blockId); item.update(response, blockId);
if (protyle) { if (protyle) {
item.updateDocTitle(protyle.background.ial, response.data?.length); item.updateDocTitle(protyle.background.ial, response.data?.length || 0);
if (getSelection().rangeCount > 0) { if (getSelection().rangeCount > 0) {
const startContainer = getSelection().getRangeAt(0).startContainer; const startContainer = getSelection().getRangeAt(0).startContainer;
if (protyle.wysiwyg.element.contains(startContainer)) { if (protyle.wysiwyg.element.contains(startContainer)) {

View file

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

View file

@ -613,9 +613,6 @@ export class Dock {
blockId: editor?.protyle?.block?.rootID, blockId: editor?.protyle?.block?.rootID,
isPreview: editor?.protyle?.preview ? !editor.protyle.preview.element.classList.contains("fn__none") : false 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); tab.addModel(outline);
} }
}); });