mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
🎨 Improve dynamic anchor text auto-refresh stability https://github.com/siyuan-note/siyuan/issues/8234
This commit is contained in:
parent
0557040064
commit
ca17aee797
2 changed files with 20 additions and 15 deletions
|
|
@ -1434,24 +1434,22 @@ func refreshDynamicRefText(updatedDefNode *ast.Node, updatedTree *parse.Tree) {
|
||||||
// refreshDynamicRefTexts 用于批量刷新块引用的动态锚文本。
|
// refreshDynamicRefTexts 用于批量刷新块引用的动态锚文本。
|
||||||
// 该实现依赖了数据库缓存,导致外部调用时可能需要阻塞等待数据库写入后才能获取到 refs
|
// 该实现依赖了数据库缓存,导致外部调用时可能需要阻塞等待数据库写入后才能获取到 refs
|
||||||
func refreshDynamicRefTexts(updatedDefNodes map[string]*ast.Node, updatedTrees map[string]*parse.Tree) {
|
func refreshDynamicRefTexts(updatedDefNodes map[string]*ast.Node, updatedTrees map[string]*parse.Tree) {
|
||||||
// 1. 更新引用的动态锚文本
|
// 更新引用的动态锚文本
|
||||||
treeRefNodeIDs := map[string]*hashset.Set{}
|
treeRefNodeIDs := map[string]*hashset.Set{}
|
||||||
for _, updateNode := range updatedDefNodes {
|
for _, updateNode := range updatedDefNodes {
|
||||||
refs := sql.GetRefsCacheByDefID(updateNode.ID)
|
refs := sql.GetRefsCacheByDefID(updateNode.ID)
|
||||||
if nil != updateNode.Parent && ast.NodeDocument != updateNode.Parent.Type &&
|
if nil != updateNode.Parent && ast.NodeDocument != updateNode.Parent.Type &&
|
||||||
updateNode.Parent.IsContainerBlock() && (updateNode == treenode.FirstLeafBlock(updateNode.Parent)) { // 容器块下第一个子块
|
updateNode.Parent.IsContainerBlock() && updateNode == treenode.FirstLeafBlock(updateNode.Parent) { // 容器块下第一个叶子块
|
||||||
var parentRefs []*sql.Ref
|
// 如果是容器块下第一个叶子块,则需要向上查找引用
|
||||||
if ast.NodeListItem == updateNode.Parent.Type { // 引用列表块时动态锚文本未跟随定义块内容变动 https://github.com/siyuan-note/siyuan/issues/4393
|
for parent := updateNode.Parent; nil != parent; parent = parent.Parent {
|
||||||
parentRefs = sql.GetRefsCacheByDefID(updateNode.Parent.Parent.ID)
|
if ast.NodeDocument == parent.Type {
|
||||||
updatedDefNodes[updateNode.Parent.ID] = updateNode.Parent
|
break
|
||||||
updatedDefNodes[updateNode.Parent.Parent.ID] = updateNode.Parent.Parent
|
}
|
||||||
} else {
|
|
||||||
parentRefs = sql.GetRefsCacheByDefID(updateNode.Parent.ID)
|
|
||||||
updatedDefNodes[updateNode.Parent.ID] = updateNode.Parent
|
|
||||||
}
|
|
||||||
|
|
||||||
if 0 < len(parentRefs) {
|
parentRefs := sql.GetRefsCacheByDefID(parent.ID)
|
||||||
refs = append(refs, parentRefs...)
|
if 0 < len(parentRefs) {
|
||||||
|
refs = append(refs, parentRefs...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, ref := range refs {
|
for _, ref := range refs {
|
||||||
|
|
@ -1488,6 +1486,9 @@ func refreshDynamicRefTexts(updatedDefNodes map[string]*ast.Node, updatedTrees m
|
||||||
if !refTreeChanged && changed {
|
if !refTreeChanged && changed {
|
||||||
refTreeChanged = true
|
refTreeChanged = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 推送动态锚文本节点刷新
|
||||||
|
util.PushReloadBlock(refTreeID, n.ID)
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
|
|
@ -1498,7 +1499,7 @@ func refreshDynamicRefTexts(updatedDefNodes map[string]*ast.Node, updatedTrees m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 更新属性视图主键内容
|
// 更新属性视图主键内容
|
||||||
for _, updatedDefNode := range updatedDefNodes {
|
for _, updatedDefNode := range updatedDefNodes {
|
||||||
avs := updatedDefNode.IALAttr(av.NodeAttrNameAvs)
|
avs := updatedDefNode.IALAttr(av.NodeAttrNameAvs)
|
||||||
if "" == avs {
|
if "" == avs {
|
||||||
|
|
@ -1535,7 +1536,7 @@ func refreshDynamicRefTexts(updatedDefNodes map[string]*ast.Node, updatedTrees m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 保存变更
|
// 保存变更
|
||||||
for _, tree := range changedRefTree {
|
for _, tree := range changedRefTree {
|
||||||
indexWriteTreeUpsertQueue(tree)
|
indexWriteTreeUpsertQueue(tree)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,10 @@ func PushProtyleReload(rootID string) {
|
||||||
BroadcastByType("protyle", "reload", 0, "", rootID)
|
BroadcastByType("protyle", "reload", 0, "", rootID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PushReloadBlock(rootID, blockID string) {
|
||||||
|
BroadcastByType("main", "reloadBlock", 0, "", map[string]interface{}{"rootID": rootID, "blockID": blockID})
|
||||||
|
}
|
||||||
|
|
||||||
func PushProtyleLoading(rootID, msg string) {
|
func PushProtyleLoading(rootID, msg string) {
|
||||||
BroadcastByType("protyle", "addLoading", 0, msg, rootID)
|
BroadcastByType("protyle", "addLoading", 0, msg, rootID)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue