mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-28 20:38:49 +01:00
🎨 Remove rows in database bound to child blocks when deleting parent block https://github.com/siyuan-note/siyuan/issues/10923
This commit is contained in:
parent
c148659fd1
commit
20ecabc6c3
1 changed files with 36 additions and 23 deletions
|
|
@ -811,35 +811,48 @@ func removeAvBlockRel(node *ast.Node) {
|
|||
}
|
||||
|
||||
func syncDelete2AttributeView(node *ast.Node) {
|
||||
avs := node.IALAttr(av.NodeAttrNameAvs)
|
||||
if "" == avs {
|
||||
return
|
||||
}
|
||||
|
||||
avIDs := strings.Split(avs, ",")
|
||||
for _, avID := range avIDs {
|
||||
attrView, parseErr := av.ParseAttributeView(avID)
|
||||
if nil != parseErr {
|
||||
continue
|
||||
changedAvIDs := hashset.New()
|
||||
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering || !n.IsBlock() {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
changedAv := false
|
||||
blockValues := attrView.GetBlockKeyValues()
|
||||
if nil == blockValues {
|
||||
continue
|
||||
avs := n.IALAttr(av.NodeAttrNameAvs)
|
||||
if "" == avs {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
for i, blockValue := range blockValues.Values {
|
||||
if blockValue.Block.ID == node.ID {
|
||||
blockValues.Values = append(blockValues.Values[:i], blockValues.Values[i+1:]...)
|
||||
changedAv = true
|
||||
break
|
||||
avIDs := strings.Split(avs, ",")
|
||||
for _, avID := range avIDs {
|
||||
attrView, parseErr := av.ParseAttributeView(avID)
|
||||
if nil != parseErr {
|
||||
continue
|
||||
}
|
||||
|
||||
changedAv := false
|
||||
blockValues := attrView.GetBlockKeyValues()
|
||||
if nil == blockValues {
|
||||
continue
|
||||
}
|
||||
|
||||
for i, blockValue := range blockValues.Values {
|
||||
if blockValue.Block.ID == n.ID {
|
||||
blockValues.Values = append(blockValues.Values[:i], blockValues.Values[i+1:]...)
|
||||
changedAv = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if changedAv {
|
||||
av.SaveAttributeView(attrView)
|
||||
changedAvIDs.Add(avID)
|
||||
}
|
||||
}
|
||||
if changedAv {
|
||||
av.SaveAttributeView(attrView)
|
||||
util.BroadcastByType("protyle", "refreshAttributeView", 0, "", map[string]interface{}{"id": avID})
|
||||
}
|
||||
return ast.WalkContinue
|
||||
})
|
||||
|
||||
for _, avID := range changedAvIDs.Values() {
|
||||
util.BroadcastByType("protyle", "refreshAttributeView", 0, "", map[string]interface{}{"id": avID})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue