mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-04 20:00:17 +01:00
🐛 Outdent of list items causes database bind blocks to be deleted https://github.com/siyuan-note/siyuan/issues/17108
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
f72cbf99a0
commit
8c8aaa6a69
2 changed files with 52 additions and 42 deletions
|
|
@ -1603,7 +1603,7 @@ func removeDoc(box *Box, p string, luteEngine *lute.Lute) (ret *parse.Tree) {
|
|||
continue
|
||||
}
|
||||
|
||||
syncDelete2AvBlock(removeTree.Root, removeTree, nil)
|
||||
syncDelete2AvBlock(removeTree.Root, removeTree, true, nil)
|
||||
}
|
||||
|
||||
if existChildren {
|
||||
|
|
|
|||
|
|
@ -1011,12 +1011,12 @@ func (tx *Transaction) doDelete0(operation *Operation, tree *parse.Tree) {
|
|||
}
|
||||
|
||||
if needSyncDel2AvBlock {
|
||||
syncDelete2AvBlock(node, tree, tx)
|
||||
syncDelete2AvBlock(node, tree, true, tx)
|
||||
}
|
||||
}
|
||||
|
||||
func syncDelete2AvBlock(node *ast.Node, nodeTree *parse.Tree, tx *Transaction) {
|
||||
changedAvIDs := syncDelete2AttributeView(node)
|
||||
func syncDelete2AvBlock(node *ast.Node, nodeTree *parse.Tree, delChildrenWhenDelParent bool, tx *Transaction) {
|
||||
changedAvIDs := syncDelete2AttributeView(node, delChildrenWhenDelParent)
|
||||
avIDs := tx.syncDelete2Block(node, nodeTree)
|
||||
changedAvIDs = append(changedAvIDs, avIDs...)
|
||||
changedAvIDs = gulu.Str.RemoveDuplicatedElem(changedAvIDs)
|
||||
|
|
@ -1078,48 +1078,18 @@ func (tx *Transaction) syncDelete2Block(node *ast.Node, nodeTree *parse.Tree) (c
|
|||
return
|
||||
}
|
||||
|
||||
func syncDelete2AttributeView(node *ast.Node) (changedAvIDs []string) {
|
||||
func syncDelete2AttributeView(node *ast.Node, delChildrenWhenDelParent bool) (changedAvIDs []string) {
|
||||
if !delChildrenWhenDelParent {
|
||||
changedAvIDs = deleteAttrView(node, changedAvIDs)
|
||||
return
|
||||
}
|
||||
|
||||
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering || !n.IsBlock() {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
avs := n.IALAttr(av.NodeAttrNameAvs)
|
||||
if "" == avs {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
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 nil == blockValue.Block {
|
||||
continue
|
||||
}
|
||||
|
||||
if blockValue.Block.ID == n.ID {
|
||||
blockValues.Values = append(blockValues.Values[:i], blockValues.Values[i+1:]...)
|
||||
changedAv = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if changedAv {
|
||||
regenAttrViewGroups(attrView)
|
||||
av.SaveAttributeView(attrView)
|
||||
changedAvIDs = append(changedAvIDs, avID)
|
||||
}
|
||||
}
|
||||
changedAvIDs = append(changedAvIDs, deleteAttrView(n, changedAvIDs)...)
|
||||
return ast.WalkContinue
|
||||
})
|
||||
|
||||
|
|
@ -1127,6 +1097,46 @@ func syncDelete2AttributeView(node *ast.Node) (changedAvIDs []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func deleteAttrView(n *ast.Node, changedAvIDs []string) []string {
|
||||
avs := n.IALAttr(av.NodeAttrNameAvs)
|
||||
if "" == avs {
|
||||
return nil
|
||||
}
|
||||
|
||||
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 nil == blockValue.Block {
|
||||
continue
|
||||
}
|
||||
|
||||
if blockValue.Block.ID == n.ID {
|
||||
blockValues.Values = append(blockValues.Values[:i], blockValues.Values[i+1:]...)
|
||||
changedAv = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if changedAv {
|
||||
regenAttrViewGroups(attrView)
|
||||
av.SaveAttributeView(attrView)
|
||||
changedAvIDs = append(changedAvIDs, avID)
|
||||
}
|
||||
}
|
||||
return changedAvIDs
|
||||
}
|
||||
|
||||
func (tx *Transaction) doLargeInsert(operations []*Operation) {
|
||||
tree, _ := tx.loadTree(operations[0].ID)
|
||||
if nil == tree {
|
||||
|
|
@ -1482,7 +1492,7 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
|||
|
||||
removedNodes := getRemovedNodes(oldNode, updatedNode)
|
||||
for _, n := range removedNodes {
|
||||
syncDelete2AvBlock(n, tree, tx)
|
||||
syncDelete2AvBlock(n, tree, false, tx)
|
||||
}
|
||||
|
||||
// 将不属于折叠标题的块移动到折叠标题下方,需要展开折叠标题
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue