🎨 Display top-level heading count in sidebar outline https://ld246.com/article/1763294247146 (#16360)

This commit is contained in:
Jeffrey Chen 2025-11-17 20:23:29 +08:00 committed by GitHub
parent 1ccce5e013
commit 72ed9c37f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 5 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);
item.updateDocTitle(protyle.background.ial, response.data?.length);
if (getSelection().rangeCount > 0) {
const startContainer = getSelection().getRangeAt(0).startContainer;
if (protyle.wysiwyg.element.contains(startContainer)) {

View file

@ -475,7 +475,7 @@ export class Outline extends Model {
});
}
public updateDocTitle(ial?: IObject) {
public updateDocTitle(ial?: IObject, count?: number) {
const docTitleElement = this.headerElement.nextElementSibling as HTMLElement;
if (this.type === "pin") {
if (ial) {
@ -483,13 +483,27 @@ export class Outline extends Model {
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.setAttribute("title", ial.title);
docTitleElement.classList.remove("fn__none");
} else {
} else if (count === undefined) {
docTitleElement.classList.add("fn__none");
}
if (count !== undefined && docTitleElement) {
const textElement = docTitleElement.querySelector(".b3-list-item__text");
if (textElement) {
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>`);
}
} else {
counterElement?.remove();
}
}
}
} else {
docTitleElement.classList.add("fn__none");
}
@ -629,6 +643,7 @@ 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 => {