🎨 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 22:59:28 +08:00
parent 09b23754db
commit c61d412fea
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -1696,38 +1696,41 @@ func setAttributeViewName(operation *Operation) (err error) {
nodes := getAttrViewBoundNodes(attrView)
for _, node := range nodes {
oldAttrs := parse.IAL2Map(node.KramdownIAL)
nodeAvIDsVal := oldAttrs[av.NodeAttrNameAvs]
if "" == nodeAvIDsVal {
avNames := getNodeIALAvNames(node)
if "" == avNames {
continue
}
node.SetIALAttr("av-names", avNames)
pushBroadcastAttrTransactions(oldAttrs, node)
}
return
}
avNames := bytes.Buffer{}
nodeAvIDs := strings.Split(nodeAvIDsVal, ",")
for _, nodeAvID := range nodeAvIDs {
var nodeAvName string
var getErr error
if nodeAvID == avID {
nodeAvName = attrView.Name
} else {
nodeAvName, getErr = av.GetAttributeViewName(nodeAvID)
if nil != getErr {
continue
}
}
if "" == nodeAvName {
nodeAvName = "Untitled"
}
func getNodeIALAvNames(node *ast.Node) (ret string) {
avIDs := parse.IAL2Map(node.KramdownIAL)[av.NodeAttrNameAvs]
if "" == avIDs {
return
}
tpl := strings.ReplaceAll(attrAvNameTpl, "${avID}", nodeAvID)
tpl = strings.ReplaceAll(tpl, "${avName}", nodeAvName)
avNames.WriteString(tpl)
avNames.WriteString(" ")
avNames := bytes.Buffer{}
nodeAvIDs := strings.Split(avIDs, ",")
for _, nodeAvID := range nodeAvIDs {
nodeAvName, getErr := av.GetAttributeViewName(nodeAvID)
if nil != getErr {
continue
}
if 0 < avNames.Len() {
avNames.Truncate(avNames.Len() - 6)
node.SetIALAttr("av-names", avNames.String())
pushBroadcastAttrTransactions(oldAttrs, node)
if "" == nodeAvName {
nodeAvName = "Untitled"
}
tpl := strings.ReplaceAll(attrAvNameTpl, "${avID}", nodeAvID)
tpl = strings.ReplaceAll(tpl, "${avName}", nodeAvName)
avNames.WriteString(tpl)
avNames.WriteString("&nbsp;")
}
if 0 < avNames.Len() {
avNames.Truncate(avNames.Len() - 6)
ret = avNames.String()
}
return
}
@ -2053,6 +2056,11 @@ func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID string,
attrs[av.NodeAttrNameAvs] = strings.Join(avIDs, ",")
}
avNames := getNodeIALAvNames(node)
if "" != avNames {
attrs["av-names"] = avNames
}
if nil != tx {
if err = setNodeAttrsWithTx(tx, node, tree, attrs); nil != err {
return