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