🎨 Display the database title on the block superscript https://github.com/siyuan-note/siyuan/issues/10545

This commit is contained in:
Daniel 2024-03-08 23:12:33 +08:00
parent c61d412fea
commit 71b8ddb2e8
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 6 additions and 29 deletions

View file

@ -1695,23 +1695,18 @@ func setAttributeViewName(operation *Operation) (err error) {
nodes := getAttrViewBoundNodes(attrView) nodes := getAttrViewBoundNodes(attrView)
for _, node := range nodes { for _, node := range nodes {
avNames := getAvNames(node.IALAttr(av.NodeAttrNameAvs))
oldAttrs := parse.IAL2Map(node.KramdownIAL) oldAttrs := parse.IAL2Map(node.KramdownIAL)
avNames := getNodeIALAvNames(node)
if "" == avNames {
continue
}
node.SetIALAttr("av-names", avNames) node.SetIALAttr("av-names", avNames)
pushBroadcastAttrTransactions(oldAttrs, node) pushBroadcastAttrTransactions(oldAttrs, node)
} }
return return
} }
func getNodeIALAvNames(node *ast.Node) (ret string) { func getAvNames(avIDs string) (ret string) {
avIDs := parse.IAL2Map(node.KramdownIAL)[av.NodeAttrNameAvs]
if "" == avIDs { if "" == avIDs {
return return
} }
avNames := bytes.Buffer{} avNames := bytes.Buffer{}
nodeAvIDs := strings.Split(avIDs, ",") nodeAvIDs := strings.Split(avIDs, ",")
for _, nodeAvID := range nodeAvIDs { for _, nodeAvID := range nodeAvIDs {
@ -2056,7 +2051,7 @@ func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID string,
attrs[av.NodeAttrNameAvs] = strings.Join(avIDs, ",") attrs[av.NodeAttrNameAvs] = strings.Join(avIDs, ",")
} }
avNames := getNodeIALAvNames(node) avNames := getAvNames(attrs[av.NodeAttrNameAvs])
if "" != avNames { if "" != avNames {
attrs["av-names"] = avNames attrs["av-names"] = avNames
} }

View file

@ -17,7 +17,6 @@
package model package model
import ( import (
"bytes"
"errors" "errors"
"fmt" "fmt"
"os" "os"
@ -735,26 +734,9 @@ func GetDoc(startID, endID, id string, index int, query string, queryTypes map[s
if avs := n.IALAttr(av.NodeAttrNameAvs); "" != avs { if avs := n.IALAttr(av.NodeAttrNameAvs); "" != avs {
// 填充属性视图角标 Display the database title on the block superscript https://github.com/siyuan-note/siyuan/issues/10545 // 填充属性视图角标 Display the database title on the block superscript https://github.com/siyuan-note/siyuan/issues/10545
avNames := bytes.Buffer{} avNames := getAvNames(n.IALAttr(av.NodeAttrNameAvs))
avIDs := strings.Split(avs, ",") if "" != avNames {
for _, avID := range avIDs { n.SetIALAttr("av-names", avNames)
avName, getErr := av.GetAttributeViewName(avID)
if nil != getErr {
continue
}
if "" == avName {
avName = "Untitled"
}
tpl := strings.ReplaceAll(attrAvNameTpl, "${avID}", avID)
tpl = strings.ReplaceAll(tpl, "${avName}", avName)
avNames.WriteString(tpl)
avNames.WriteString(" ")
}
if 0 < avNames.Len() {
avNames.Truncate(avNames.Len() - 6)
n.SetIALAttr("av-names", avNames.String())
} }
} }