From 1feecff511ff3510026e1a9317040c59fba8180b Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 30 Sep 2022 22:26:04 +0800 Subject: [PATCH 1/3] =?UTF-8?q?:fire:=20=E7=A7=BB=E9=99=A4=E6=97=A9?= =?UTF-8?q?=E6=9C=9F=E7=9A=84=E5=8A=A8=E6=80=81=E9=94=9A=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E9=9D=99=E6=80=81=E5=8C=96=E8=BF=81=E7=A7=BB=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/index.go | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/kernel/model/index.go b/kernel/model/index.go index 2bc5fb033..0087a6f88 100644 --- a/kernel/model/index.go +++ b/kernel/model/index.go @@ -24,9 +24,7 @@ import ( "sort" "strings" "time" - "unicode/utf8" - "github.com/88250/gulu" "github.com/88250/lute/ast" "github.com/88250/lute/parse" "github.com/dustin/go-humanize" @@ -251,7 +249,7 @@ func IndexRefs() { logging.LogErrorf("tree [%s] dynamic ref text to static failed: %s", dynamicRefTreeID, err) continue } - legacyDynamicRefTreeToStatic(tree) + if err := filesys.WriteTree(tree); nil == err { //logging.LogInfof("persisted tree [%s] dynamic ref text", tree.Box+tree.Path) } @@ -319,35 +317,6 @@ func IndexRefs() { logging.LogInfof("resolved refs [%d] in [%dms]", len(refBlocks), time.Now().Sub(start).Milliseconds()) } -func legacyDynamicRefTreeToStatic(tree *parse.Tree) { - ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus { - if !entering || ast.NodeBlockRef != n.Type { - return ast.WalkContinue - } - if isLegacyDynamicBlockRef(n) { - idNode := n.ChildByType(ast.NodeBlockRefID) - defID := idNode.TokensStr() - def := sql.GetBlock(defID) - var text string - if nil == def { - if "zh_CN" == Conf.Lang { - text = "解析引用锚文本失败,请尝试更新该引用指向的定义块后再重新打开该文档" - } else { - text = "Failed to parse the ref anchor text, please try to update the def block pointed to by the ref and then reopen this document" - } - } else { - text = sql.GetRefText(defID) - } - if Conf.Editor.BlockRefDynamicAnchorTextMaxLen < utf8.RuneCountInString(text) { - text = gulu.Str.SubStr(text, Conf.Editor.BlockRefDynamicAnchorTextMaxLen) + "..." - } - treenode.SetDynamicBlockRefText(n, text) - return ast.WalkSkipChildren - } - return ast.WalkContinue - }) -} - func isLegacyDynamicBlockRef(blockRef *ast.Node) bool { return nil == blockRef.ChildByType(ast.NodeBlockRefText) && nil == blockRef.ChildByType(ast.NodeBlockRefDynamicText) } From 3555df9267c7d318df4891980c94fcd9a9b0fbd2 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 30 Sep 2022 22:33:24 +0800 Subject: [PATCH 2/3] =?UTF-8?q?:recycle:=20=E6=8F=90=E5=8F=96=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=20node=20=E9=94=9A=E6=96=87=E6=9C=AC=E7=9A=84?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/blockinfo.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/model/blockinfo.go b/kernel/model/blockinfo.go index bb90de4b7..0d2a4a669 100644 --- a/kernel/model/blockinfo.go +++ b/kernel/model/blockinfo.go @@ -91,7 +91,10 @@ func GetBlockRefText(id string) string { if nil == node { return ErrBlockNotFound.Error() } + return getNodeRefText(node) +} +func getNodeRefText(node *ast.Node) string { if name := node.IALAttr("name"); "" != name { return name } From 801e5d12e1926d4ce6dc0fc1bd2e8f647286785b Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 30 Sep 2022 22:33:41 +0800 Subject: [PATCH 3/3] =?UTF-8?q?:bug:=20=E5=BC=95=E7=94=A8=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E5=9D=97=E6=97=B6=E5=8A=A8=E6=80=81=E9=94=9A=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E6=B2=A1=E6=9C=89=E4=BD=BF=E7=94=A8=E5=91=BD=E5=90=8D?= =?UTF-8?q?=20Fix=20https://github.com/siyuan-note/siyuan/issues/6032?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/transaction.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index 0979a0bd6..fad01e0da 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -24,7 +24,6 @@ import ( "strings" "sync" "time" - "unicode/utf8" "github.com/88250/gulu" "github.com/88250/lute/ast" @@ -1131,11 +1130,9 @@ func updateRefText(refNode *ast.Node, changedDefNodes map[string]*ast.Node) (cha if ast.NodeDocument != defNode.Type && defNode.IsContainerBlock() { defNode = treenode.FirstLeafBlock(defNode) } - defContent := renderBlockText(defNode) - if Conf.Editor.BlockRefDynamicAnchorTextMaxLen < utf8.RuneCountInString(defContent) { - defContent = gulu.Str.SubStr(defContent, Conf.Editor.BlockRefDynamicAnchorTextMaxLen) + "..." - } - treenode.SetDynamicBlockRefText(n, defContent) + + refText := getNodeRefText(defNode) + treenode.SetDynamicBlockRefText(n, refText) changed = true return ast.WalkContinue })