mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
🎨 Improve av https://github.com/siyuan-note/siyuan/issues/15665
This commit is contained in:
parent
77c1aa49b3
commit
a5ca8efcae
1 changed files with 8 additions and 56 deletions
|
|
@ -4265,18 +4265,18 @@ func replaceAttributeViewBlock(avID, oldBlockID, newBlockID string, isDetached b
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newBlockID string, isDetached bool, tx *Transaction) (err error) {
|
func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newNodeID string, isDetached bool, tx *Transaction) (err error) {
|
||||||
avID := attrView.ID
|
avID := attrView.ID
|
||||||
var tree *parse.Tree
|
var tree *parse.Tree
|
||||||
var node *ast.Node
|
var node *ast.Node
|
||||||
if !isDetached {
|
if !isDetached {
|
||||||
node, tree, _ = getNodeByBlockID(tx, newBlockID)
|
node, tree, _ = getNodeByBlockID(tx, newNodeID)
|
||||||
}
|
}
|
||||||
|
|
||||||
now := util.CurrentTimeMillis()
|
now := util.CurrentTimeMillis()
|
||||||
// 检查是否已经存在绑定块,如果存在的话则重新绑定
|
// 检查是否已经存在绑定块,如果存在的话则重新绑定
|
||||||
for _, blockVal := range attrView.GetBlockKeyValues().Values {
|
for _, blockVal := range attrView.GetBlockKeyValues().Values {
|
||||||
if !isDetached && blockVal.Block.ID == newBlockID && nil != node && nil != tree {
|
if !isDetached && blockVal.Block.ID == newNodeID && nil != node && nil != tree {
|
||||||
bindBlockAv0(tx, avID, node, tree)
|
bindBlockAv0(tx, avID, node, tree)
|
||||||
blockVal.IsDetached = false
|
blockVal.IsDetached = false
|
||||||
icon, content := getNodeAvBlockText(node, "")
|
icon, content := getNodeAvBlockText(node, "")
|
||||||
|
|
@ -4288,7 +4288,6 @@ func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newBlock
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var changedAvIDs []string
|
|
||||||
for _, blockVal := range attrView.GetBlockKeyValues().Values {
|
for _, blockVal := range attrView.GetBlockKeyValues().Values {
|
||||||
if blockVal.BlockID != oldBlockID {
|
if blockVal.BlockID != oldBlockID {
|
||||||
continue
|
continue
|
||||||
|
|
@ -4297,17 +4296,17 @@ func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newBlock
|
||||||
if av.KeyTypeBlock == blockVal.Type {
|
if av.KeyTypeBlock == blockVal.Type {
|
||||||
blockVal.IsDetached = isDetached
|
blockVal.IsDetached = isDetached
|
||||||
if !isDetached {
|
if !isDetached {
|
||||||
if "" != blockVal.Block.ID && blockVal.Block.ID != newBlockID {
|
if "" != blockVal.Block.ID && blockVal.Block.ID != newNodeID {
|
||||||
unbindBlockAv(tx, avID, blockVal.Block.ID)
|
unbindBlockAv(tx, avID, blockVal.Block.ID)
|
||||||
}
|
}
|
||||||
bindBlockAv(tx, avID, newBlockID)
|
bindBlockAv(tx, avID, newNodeID)
|
||||||
|
|
||||||
|
blockVal.Block.ID = newNodeID
|
||||||
icon, content := getNodeAvBlockText(node, "")
|
icon, content := getNodeAvBlockText(node, "")
|
||||||
content = util.UnescapeHTML(content)
|
content = util.UnescapeHTML(content)
|
||||||
blockVal.Block.Icon, blockVal.Block.Content = icon, content
|
blockVal.Block.Icon, blockVal.Block.Content = icon, content
|
||||||
avIDs := replaceRelationAvValues(avID, blockVal.Block.ID, newBlockID)
|
|
||||||
blockVal.Block.ID = newBlockID
|
refreshRelatedSrcAvs(avID)
|
||||||
changedAvIDs = append(changedAvIDs, avIDs...)
|
|
||||||
} else {
|
} else {
|
||||||
blockVal.Block.ID = ""
|
blockVal.Block.ID = ""
|
||||||
}
|
}
|
||||||
|
|
@ -4315,11 +4314,6 @@ func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
regenAttrViewGroups(attrView, "force")
|
regenAttrViewGroups(attrView, "force")
|
||||||
|
|
||||||
changedAvIDs = gulu.Str.RemoveDuplicatedElem(changedAvIDs)
|
|
||||||
for _, id := range changedAvIDs {
|
|
||||||
ReloadAttrView(id)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5126,48 +5120,6 @@ func getAttrViewName(attrView *av.AttributeView) string {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func replaceRelationAvValues(avID, previousID, nextID string) (changedSrcAvID []string) {
|
|
||||||
// The database relation fields follow the change after the primary key field is changed https://github.com/siyuan-note/siyuan/issues/11117
|
|
||||||
|
|
||||||
srcAvIDs := av.GetSrcAvIDs(avID)
|
|
||||||
for _, srcAvID := range srcAvIDs {
|
|
||||||
srcAv, parseErr := av.ParseAttributeView(srcAvID)
|
|
||||||
changed := false
|
|
||||||
if nil != parseErr {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, srcKeyValues := range srcAv.KeyValues {
|
|
||||||
if av.KeyTypeRelation != srcKeyValues.Key.Type {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if nil == srcKeyValues.Key.Relation || avID != srcKeyValues.Key.Relation.AvID {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, srcValue := range srcKeyValues.Values {
|
|
||||||
if nil == srcValue.Relation {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
srcAvChanged := false
|
|
||||||
srcValue.Relation.BlockIDs, srcAvChanged = util.ReplaceStr(srcValue.Relation.BlockIDs, previousID, nextID)
|
|
||||||
if srcAvChanged {
|
|
||||||
changed = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if changed {
|
|
||||||
regenAttrViewGroups(srcAv, "force")
|
|
||||||
av.SaveAttributeView(srcAv)
|
|
||||||
changedSrcAvID = append(changedSrcAvID, srcAvID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateBoundBlockAvsAttribute(avIDs []string) {
|
func updateBoundBlockAvsAttribute(avIDs []string) {
|
||||||
// 更新指定 avIDs 中绑定块的 avs 属性
|
// 更新指定 avIDs 中绑定块的 avs 属性
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue