Browse Source

:bug: 偶发编辑文档标题后引用处的动态锚文本不更新 Fix https://github.com/siyuan-note/siyuan/issues/5891

Liang Ding 2 years ago
parent
commit
5861be23ee
3 changed files with 18 additions and 4 deletions
  1. 10 2
      kernel/model/transaction.go
  2. 2 2
      kernel/sql/cache.go
  3. 6 0
      kernel/treenode/node.go

+ 10 - 2
kernel/model/transaction.go

@@ -886,11 +886,19 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
 				if "" == strings.TrimSpace(n.TextMarkInlineMathContent) {
 				if "" == strings.TrimSpace(n.TextMarkInlineMathContent) {
 					unlinks = append(unlinks, n)
 					unlinks = append(unlinks, n)
 				}
 				}
+			} else if n.IsTextMarkType("block-ref") {
+				sql.CacheRef(subTree, n)
+
+				if "d" == n.TextMarkBlockRefSubtype {
+					// 偶发编辑文档标题后引用处的动态锚文本不更新 https://github.com/siyuan-note/siyuan/issues/5891
+					// 使用缓存的动态锚文本强制覆盖当前块中的引用节点动态锚文本
+					if dRefText, ok := treenode.DynamicRefTexts.Load(n.TextMarkBlockRefID); ok && "" != dRefText {
+						n.TextMarkTextContent = dRefText.(string)
+					}
+				}
 			}
 			}
 		} else if ast.NodeBlockRef == n.Type {
 		} else if ast.NodeBlockRef == n.Type {
 			sql.CacheRef(subTree, n)
 			sql.CacheRef(subTree, n)
-		} else if ast.NodeTextMark == n.Type && n.IsTextMarkType("block-ref") {
-			sql.CacheRef(subTree, n)
 		}
 		}
 		return ast.WalkContinue
 		return ast.WalkContinue
 	})
 	})

+ 2 - 2
kernel/sql/cache.go

@@ -93,6 +93,8 @@ func ClearVirtualRefKeywords() {
 	memCache.Del("virtual_ref")
 	memCache.Del("virtual_ref")
 }
 }
 
 
+var defIDRefsCache = gcache.New(30*time.Minute, 5*time.Minute) // [defBlockID]map[refBlockID]*Ref
+
 func GetRefsCacheByDefID(defID string) (ret []*Ref) {
 func GetRefsCacheByDefID(defID string) (ret []*Ref) {
 	for defBlockID, refs := range defIDRefsCache.Items() {
 	for defBlockID, refs := range defIDRefsCache.Items() {
 		if defBlockID == defID {
 		if defBlockID == defID {
@@ -110,8 +112,6 @@ func GetRefsCacheByDefID(defID string) (ret []*Ref) {
 	return
 	return
 }
 }
 
 
-var defIDRefsCache = gcache.New(30*time.Minute, 5*time.Minute) // [defBlockID]map[refBlockID]*Ref
-
 func CacheRef(tree *parse.Tree, refNode *ast.Node) {
 func CacheRef(tree *parse.Tree, refNode *ast.Node) {
 	ref := buildRef(tree, refNode)
 	ref := buildRef(tree, refNode)
 	putRefCache(ref)
 	putRefCache(ref)

+ 6 - 0
kernel/treenode/node.go

@@ -19,6 +19,7 @@ package treenode
 import (
 import (
 	"bytes"
 	"bytes"
 	"strings"
 	"strings"
+	"sync"
 
 
 	"github.com/88250/lute"
 	"github.com/88250/lute"
 	"github.com/88250/lute/ast"
 	"github.com/88250/lute/ast"
@@ -358,6 +359,8 @@ func GetLegacyDynamicBlockRefDefIDs(node *ast.Node) (ret []string) {
 	return
 	return
 }
 }
 
 
+var DynamicRefTexts = sync.Map{}
+
 func SetDynamicBlockRefText(blockRef *ast.Node, refText string) {
 func SetDynamicBlockRefText(blockRef *ast.Node, refText string) {
 	if !IsBlockRef(blockRef) {
 	if !IsBlockRef(blockRef) {
 		return
 		return
@@ -384,6 +387,9 @@ func SetDynamicBlockRefText(blockRef *ast.Node, refText string) {
 
 
 	blockRef.TextMarkBlockRefSubtype = "d"
 	blockRef.TextMarkBlockRefSubtype = "d"
 	blockRef.TextMarkTextContent = refText
 	blockRef.TextMarkTextContent = refText
+
+	// 偶发编辑文档标题后引用处的动态锚文本不更新 https://github.com/siyuan-note/siyuan/issues/5891
+	DynamicRefTexts.Store(blockRef.TextMarkBlockRefID, refText)
 }
 }
 
 
 func GetDynamicBlockRefText(blockRef *ast.Node) string {
 func GetDynamicBlockRefText(blockRef *ast.Node) string {