Vanessa 2024-12-30 17:43:13 +08:00
parent 4228160cb2
commit 7f53b9e311
2 changed files with 12 additions and 7 deletions

View file

@ -145,13 +145,13 @@ export const countSelectWord = (range: Range, rootID?: string) => {
const selectText = range.toString();
if (selectText) {
fetchPost("/api/block/getContentWordCount", {"content": range.toString()}, (response) => {
renderStatusbarCounter(response.data);
renderStatusbarCounter(response.data.stat);
});
countRootId = "";
} else if (rootID && rootID !== countRootId) {
countRootId = rootID;
fetchPost("/api/block/getTreeStat", {id: rootID}, (response) => {
renderStatusbarCounter(response.data);
renderStatusbarCounter(response.data.stat);
});
}
}, Constants.TIMEOUT_COUNT);
@ -163,6 +163,10 @@ export const countBlockWord = (ids: string[], rootID?: string, clearCache = fals
if (document.getElementById("status").classList.contains("fn__none")) {
return;
}
if (getSelection().rangeCount > 0 && getSelection().getRangeAt(0).toString()) {
countSelectWord(getSelection().getRangeAt(0));
return;
}
clearTimeout(countTimeout);
countTimeout = window.setTimeout(() => {
if (clearCache) {
@ -170,13 +174,13 @@ export const countBlockWord = (ids: string[], rootID?: string, clearCache = fals
}
if (ids.length > 0) {
fetchPost("/api/block/getBlocksWordCount", {ids}, (response) => {
renderStatusbarCounter(response.data);
renderStatusbarCounter(response.data.stat);
});
countRootId = "";
} else if (rootID && rootID !== countRootId) {
countRootId = rootID;
fetchPost("/api/block/getTreeStat", {id: rootID}, (response) => {
renderStatusbarCounter(response.data);
renderStatusbarCounter(response.data.stat);
});
}
}, Constants.TIMEOUT_COUNT);
@ -210,7 +214,8 @@ export const renderStatusbarCounter = (stat: {
}
if (0 < stat.refCount) {
html += `<span class="ft__on-surface">${window.siyuan.languages.refCount}</span>&nbsp;${stat.refCount}<span class="fn__space"></span>`;
}if (0 < stat.blockCount) {
}
if (0 < stat.blockCount) {
html += `<span class="ft__on-surface">${window.siyuan.languages.blockCount}</span>&nbsp;${stat.blockCount}<span class="fn__space"></span>`;
}
document.querySelector("#status .status__counter").innerHTML = html;

View file

@ -565,7 +565,7 @@ ${padHTML}
type: "open-menu-breadcrumbmore",
detail: {
protyle,
data: response.data,
data: response.data.stat,
},
separatorPosition: "top",
});
@ -576,7 +576,7 @@ ${padHTML}
iconHTML: "",
type: "readonly",
// 不能换行,否则移动端间距过大
label: `<div class="fn__flex">${window.siyuan.languages.runeCount}<span class="fn__space fn__flex-1"></span>${response.data.runeCount}</div><div class="fn__flex">${window.siyuan.languages.wordCount}<span class="fn__space fn__flex-1"></span>${response.data.wordCount}</div><div class="fn__flex">${window.siyuan.languages.linkCount}<span class="fn__space fn__flex-1"></span>${response.data.linkCount}</div><div class="fn__flex">${window.siyuan.languages.imgCount}<span class="fn__space fn__flex-1"></span>${response.data.imageCount}</div><div class="fn__flex">${window.siyuan.languages.refCount}<span class="fn__space fn__flex-1"></span>${response.data.refCount}</div><div class="fn__flex">${window.siyuan.languages.blockCount}<span class="fn__space fn__flex-1"></span>${response.data.blockCount}</div>`,
label: `<div class="fn__flex">${window.siyuan.languages.runeCount}<span class="fn__space fn__flex-1"></span>${response.data.stat.runeCount}</div><div class="fn__flex">${window.siyuan.languages.wordCount}<span class="fn__space fn__flex-1"></span>${response.data.stat.wordCount}</div><div class="fn__flex">${window.siyuan.languages.linkCount}<span class="fn__space fn__flex-1"></span>${response.data.stat.linkCount}</div><div class="fn__flex">${window.siyuan.languages.imgCount}<span class="fn__space fn__flex-1"></span>${response.data.stat.imageCount}</div><div class="fn__flex">${window.siyuan.languages.refCount}<span class="fn__space fn__flex-1"></span>${response.data.stat.refCount}</div><div class="fn__flex">${window.siyuan.languages.blockCount}<span class="fn__space fn__flex-1"></span>${response.data.stat.blockCount}</div>`,
}).element);
/// #if MOBILE
window.siyuan.menus.menu.fullscreen();