🎨 Improve db block editing https://github.com/siyuan-note/siyuan/issues/13031
This commit is contained in:
parent
141374b7c1
commit
dc70276dae
2 changed files with 17 additions and 7 deletions
|
@ -1715,16 +1715,16 @@ func getAvNames(avIDs string) (ret string) {
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) getAttrViewBoundNodes(attrView *av.AttributeView) (trees []*parse.Tree, nodes []*ast.Node) {
|
||||
func (tx *Transaction) getAttrViewBoundNodes(attrView *av.AttributeView) (trees map[string]*parse.Tree, nodes []*ast.Node) {
|
||||
blockKeyValues := attrView.GetBlockKeyValues()
|
||||
treeCache := map[string]*parse.Tree{}
|
||||
trees = map[string]*parse.Tree{}
|
||||
for _, blockKeyValue := range blockKeyValues.Values {
|
||||
if blockKeyValue.IsDetached {
|
||||
continue
|
||||
}
|
||||
|
||||
var tree *parse.Tree
|
||||
tree = treeCache[blockKeyValue.BlockID]
|
||||
tree = trees[blockKeyValue.BlockID]
|
||||
if nil == tree {
|
||||
if nil == tx {
|
||||
tree, _ = LoadTreeByBlockID(blockKeyValue.BlockID)
|
||||
|
@ -1735,7 +1735,7 @@ func (tx *Transaction) getAttrViewBoundNodes(attrView *av.AttributeView) (trees
|
|||
if nil == tree {
|
||||
continue
|
||||
}
|
||||
treeCache[blockKeyValue.BlockID] = tree
|
||||
trees[blockKeyValue.BlockID] = tree
|
||||
|
||||
node := treenode.GetNodeInTree(tree, blockKeyValue.BlockID)
|
||||
if nil == node {
|
||||
|
@ -1744,9 +1744,6 @@ func (tx *Transaction) getAttrViewBoundNodes(attrView *av.AttributeView) (trees
|
|||
|
||||
nodes = append(nodes, node)
|
||||
}
|
||||
for _, tree := range treeCache {
|
||||
trees = append(trees, tree)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -1100,6 +1100,19 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
|||
ReloadAttrView(avID)
|
||||
}
|
||||
|
||||
// 插入数据库块时需要重新绑定其中已经存在的块
|
||||
// 比如剪切操作时,会先进行 delete 数据库解绑块,这里需要重新绑定 https://github.com/siyuan-note/siyuan/issues/13031
|
||||
if ast.NodeAttributeView == insertedNode.Type {
|
||||
attrView, parseErr := av.ParseAttributeView(insertedNode.AttributeViewID)
|
||||
if nil == parseErr {
|
||||
trees, toBindNodes := tx.getAttrViewBoundNodes(attrView)
|
||||
for _, toBindNode := range toBindNodes {
|
||||
t := trees[toBindNode.ID]
|
||||
bindBlockAv0(tx, insertedNode.AttributeViewID, toBindNode, t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
operation.ID = insertedNode.ID
|
||||
operation.ParentID = insertedNode.Parent.ID
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue