🎨 状态栏实时统计文档信息 https://github.com/siyuan-note/siyuan/issues/6036
This commit is contained in:
parent
ae8ce006ba
commit
a772b47287
6 changed files with 36 additions and 11 deletions
|
@ -9,6 +9,7 @@ import {hideMessage, showMessage} from "./message";
|
|||
import {Dialog} from "./index";
|
||||
import {isMobile} from "../util/functions";
|
||||
import {confirmDialog} from "./confirmDialog";
|
||||
import {renderStatusbarCounter} from "../layout/status";
|
||||
|
||||
export const lockFile = (id: string) => {
|
||||
const html = `<div class="b3-dialog__scrim"></div>
|
||||
|
@ -187,6 +188,10 @@ export const progressStatus = (data: IWebSocketData) => {
|
|||
document.querySelector("#status .status__msg").innerHTML = data.msg;
|
||||
};
|
||||
|
||||
export const handleStatusbarCounter = (data: IWebSocketData) => {
|
||||
renderStatusbarCounter(data.data.runeCount, data.data.wordCount);
|
||||
};
|
||||
|
||||
export const progressLoading = (data: IWebSocketData) => {
|
||||
let progressElement = document.getElementById("progress");
|
||||
if (!progressElement) {
|
||||
|
|
|
@ -12,7 +12,7 @@ import {addBaseURL, setNoteBook} from "./util/pathName";
|
|||
import {openFileById} from "./editor/util";
|
||||
import {
|
||||
bootSync,
|
||||
downloadProgress,
|
||||
downloadProgress, handleStatusbarCounter,
|
||||
progressLoading,
|
||||
progressStatus,
|
||||
setTitle,
|
||||
|
@ -48,6 +48,8 @@ class App {
|
|||
case"statusbar":
|
||||
progressStatus(data);
|
||||
break;
|
||||
case"statusbarCounter":
|
||||
handleStatusbarCounter(data)
|
||||
case"downloadProgress":
|
||||
downloadProgress(data.data);
|
||||
break;
|
||||
|
|
|
@ -137,11 +137,7 @@ export const countSelectWord = (range: Range) => {
|
|||
const selectText = range.toString();
|
||||
if (selectText) {
|
||||
fetchPost("/api/block/getContentWordCount", {"content": range.toString()}, (response) => {
|
||||
document.querySelector("#status .status__counter").innerHTML = `<span class="ft__on-surface">${window.siyuan.languages.runeCount}</span>
|
||||
${response.data.runeCount}
|
||||
<span class="fn__space"></span>
|
||||
<span class="ft__on-surface">${window.siyuan.languages.wordCount}</span>
|
||||
${response.data.wordCount}<span class="fn__space"></span>`;
|
||||
renderStatusbarCounter(response.data.runeCount, response.data.wordCount);
|
||||
});
|
||||
} else {
|
||||
document.querySelector("#status .status__counter").innerHTML = "";
|
||||
|
@ -156,11 +152,7 @@ export const countBlockWord = (ids: string[]) => {
|
|||
}
|
||||
if (ids.length > 0) {
|
||||
fetchPost("/api/block/getBlocksWordCount", {ids}, (response) => {
|
||||
document.querySelector("#status .status__counter").innerHTML = `<span class="ft__on-surface">${window.siyuan.languages.runeCount}</span>
|
||||
${response.data.runeCount}
|
||||
<span class="fn__space"></span>
|
||||
<span class="ft__on-surface">${window.siyuan.languages.wordCount}</span>
|
||||
${response.data.wordCount}<span class="fn__space"></span>`;
|
||||
renderStatusbarCounter(response.data.runeCount, response.data.wordCount);
|
||||
});
|
||||
} else {
|
||||
document.querySelector("#status .status__counter").innerHTML = "";
|
||||
|
@ -168,3 +160,10 @@ export const countBlockWord = (ids: string[]) => {
|
|||
/// #endif
|
||||
};
|
||||
|
||||
export const renderStatusbarCounter = (runeCount: number, wordCount: number) => {
|
||||
document.querySelector("#status .status__counter").innerHTML = `<span class="ft__on-surface">${window.siyuan.languages.runeCount}</span>
|
||||
${runeCount}
|
||||
<span class="fn__space"></span>
|
||||
<span class="ft__on-surface">${window.siyuan.languages.wordCount}</span>
|
||||
${wordCount}<span class="fn__space"></span>`;
|
||||
}
|
||||
|
|
|
@ -997,6 +997,8 @@ func (tx *Transaction) begin() (err error) {
|
|||
|
||||
func (tx *Transaction) commit() (err error) {
|
||||
for _, tree := range tx.trees {
|
||||
go pushTreeStat(tree)
|
||||
|
||||
if err = writeJSONQueue(tree); nil != err {
|
||||
return
|
||||
}
|
||||
|
@ -1007,6 +1009,11 @@ func (tx *Transaction) commit() (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func pushTreeStat(tree *parse.Tree) {
|
||||
runeCount, wordCount := treenode.TreeStat(tree)
|
||||
util.PushStatusBarCounter(runeCount, wordCount)
|
||||
}
|
||||
|
||||
func (tx *Transaction) rollback() {
|
||||
tx.trees, tx.nodes = nil, nil
|
||||
return
|
||||
|
|
|
@ -31,6 +31,11 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func TreeStat(tree *parse.Tree) (runeCount, wordCount int) {
|
||||
runeCount, wordCount = tree.Root.ContentLen()
|
||||
return
|
||||
}
|
||||
|
||||
func NodeHash(node *ast.Node, tree *parse.Tree, luteEngine *lute.Lute) string {
|
||||
ialArray := node.KramdownIAL
|
||||
sort.Slice(ialArray, func(i, j int) bool {
|
||||
|
|
|
@ -151,6 +151,13 @@ func PushStatusBar(msg string) {
|
|||
BroadcastByType("main", "statusbar", 0, msg, nil)
|
||||
}
|
||||
|
||||
func PushStatusBarCounter(runeCount, wordCount int) {
|
||||
BroadcastByType("main", "statusbarCounter", 0, "", map[string]interface{}{
|
||||
"runeCount": runeCount,
|
||||
"wordCount": wordCount},
|
||||
)
|
||||
}
|
||||
|
||||
func ContextPushMsg(context map[string]interface{}, msg string) {
|
||||
switch context[eventbus.CtxPushMsg].(int) {
|
||||
case eventbus.CtxPushMsgToProgress:
|
||||
|
|
Loading…
Add table
Reference in a new issue