mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 Remove av block also remove node attr https://github.com/siyuan-note/siyuan/issues/9091#issuecomment-1709824006
This commit is contained in:
parent
945e8af6be
commit
544ae88e87
1 changed files with 26 additions and 9 deletions
|
|
@ -487,14 +487,14 @@ func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tre
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Transaction) doRemoveAttrViewBlock(operation *Operation) (ret *TxErr) {
|
func (tx *Transaction) doRemoveAttrViewBlock(operation *Operation) (ret *TxErr) {
|
||||||
err := removeAttributeViewBlock(operation)
|
err := tx.removeAttributeViewBlock(operation)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID}
|
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeAttributeViewBlock(operation *Operation) (err error) {
|
func (tx *Transaction) removeAttributeViewBlock(operation *Operation) (err error) {
|
||||||
attrView, err := av.ParseAttributeView(operation.AvID)
|
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
|
|
@ -505,11 +505,35 @@ func removeAttributeViewBlock(operation *Operation) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trees := map[string]*parse.Tree{}
|
||||||
for _, keyValues := range attrView.KeyValues {
|
for _, keyValues := range attrView.KeyValues {
|
||||||
tmp := keyValues.Values[:0]
|
tmp := keyValues.Values[:0]
|
||||||
for i, values := range keyValues.Values {
|
for i, values := range keyValues.Values {
|
||||||
if !gulu.Str.Contains(values.BlockID, operation.SrcIDs) {
|
if !gulu.Str.Contains(values.BlockID, operation.SrcIDs) {
|
||||||
tmp = append(tmp, keyValues.Values[i])
|
tmp = append(tmp, keyValues.Values[i])
|
||||||
|
} else {
|
||||||
|
if bt := treenode.GetBlockTree(values.BlockID); nil != bt {
|
||||||
|
tree := trees[bt.RootID]
|
||||||
|
if nil == tree {
|
||||||
|
tree, _ = loadTreeByBlockID(values.BlockID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if nil != tree {
|
||||||
|
trees[bt.RootID] = tree
|
||||||
|
if node := treenode.GetNodeInTree(tree, values.BlockID); nil != node {
|
||||||
|
attrs := parse.IAL2Map(node.KramdownIAL)
|
||||||
|
if ast.NodeDocument == node.Type {
|
||||||
|
delete(attrs, "custom-hidden")
|
||||||
|
}
|
||||||
|
delete(attrs, NodeAttrNamePrefixAvKey+operation.AvID+"-"+values.KeyID)
|
||||||
|
node.RemoveIALAttr(NodeAttrNamePrefixAvKey + operation.AvID + "-" + values.KeyID)
|
||||||
|
|
||||||
|
if err = setNodeAttrsWithTx(tx, node, tree, attrs); nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
keyValues.Values = tmp
|
keyValues.Values = tmp
|
||||||
|
|
@ -517,13 +541,6 @@ func removeAttributeViewBlock(operation *Operation) (err error) {
|
||||||
|
|
||||||
for _, blockID := range operation.SrcIDs {
|
for _, blockID := range operation.SrcIDs {
|
||||||
view.Table.RowIDs = gulu.Str.RemoveElem(view.Table.RowIDs, blockID)
|
view.Table.RowIDs = gulu.Str.RemoveElem(view.Table.RowIDs, blockID)
|
||||||
|
|
||||||
if bt := treenode.GetBlockTree(blockID); nil != bt && "d" == bt.Type {
|
|
||||||
if tree, _ := loadTreeByBlockID(blockID); nil != tree {
|
|
||||||
tree.Root.RemoveIALAttr("custom-hidden")
|
|
||||||
writeJSONQueue(tree)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = av.SaveAttributeView(attrView)
|
err = av.SaveAttributeView(attrView)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue