diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.ts index 7d7a2793a..df17cd3d8 100644 --- a/app/src/dialog/processSystem.ts +++ b/app/src/dialog/processSystem.ts @@ -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 = `
@@ -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) { diff --git a/app/src/index.ts b/app/src/index.ts index f45cc17ca..a83419e54 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -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; diff --git a/app/src/layout/status.ts b/app/src/layout/status.ts index a2448be78..dd783b140 100644 --- a/app/src/layout/status.ts +++ b/app/src/layout/status.ts @@ -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 = `${window.siyuan.languages.runeCount} - ${response.data.runeCount} - -${window.siyuan.languages.wordCount} - ${response.data.wordCount}`; + 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 = `${window.siyuan.languages.runeCount} - ${response.data.runeCount} - -${window.siyuan.languages.wordCount} - ${response.data.wordCount}`; + 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 = `${window.siyuan.languages.runeCount} + ${runeCount} + +${window.siyuan.languages.wordCount} + ${wordCount}`; +} diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index fad01e0da..def28cf2d 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -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 diff --git a/kernel/treenode/tree.go b/kernel/treenode/tree.go index 034309833..f102ff43e 100644 --- a/kernel/treenode/tree.go +++ b/kernel/treenode/tree.go @@ -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 { diff --git a/kernel/util/websocket.go b/kernel/util/websocket.go index b7251821c..b290db176 100644 --- a/kernel/util/websocket.go +++ b/kernel/util/websocket.go @@ -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: