mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-22 16:26:09 +01:00
🎨 状态栏实时统计文档信息 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
|
|
@ -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
Add a link
Reference in a new issue