소스 검색

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

Daniel 1 년 전
부모
커밋
c61d412fea
1개의 변경된 파일34개의 추가작업 그리고 26개의 파일을 삭제
  1. 34 26
      kernel/model/attribute_view.go

+ 34 - 26
kernel/model/attribute_view.go

@@ -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