mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 Display top-level heading count in sidebar outline https://ld246.com/article/1763294247146 (#16360)
This commit is contained in:
parent
1ccce5e013
commit
72ed9c37f8
2 changed files with 20 additions and 5 deletions
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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 => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue