Ver código fonte

:art: Improve floating window backlink https://github.com/siyuan-note/siyuan/issues/13371

Daniel 7 meses atrás
pai
commit
04a4a90721
4 arquivos alterados com 22 adições e 11 exclusões
  1. 1 1
      kernel/api/block.go
  2. 20 1
      kernel/model/blockinfo.go
  3. 0 8
      kernel/model/file.go
  4. 1 1
      kernel/model/push_reload.go

+ 1 - 1
kernel/api/block.go

@@ -412,7 +412,7 @@ func getRefIDs(c *gin.Context) {
 	}
 
 	id := arg["id"].(string)
-	refIDs, refTexts, defIDs := model.GetBlockRefs(id)
+	refIDs, refTexts, defIDs := model.GetBlockRefs(id, true)
 	ret.Data = map[string][]string{
 		"refIDs":   refIDs,
 		"refTexts": refTexts,

+ 20 - 1
kernel/model/blockinfo.go

@@ -91,6 +91,7 @@ func GetDocInfo(blockID string) (ret *BlockInfo) {
 	}
 
 	ret.RefIDs, _ = sql.QueryRefIDsByDefID(blockID, false)
+	buildBacklinkListItemRefs(&ret.RefIDs)
 	ret.RefCount = len(ret.RefIDs) // 填充块引计数
 
 	// 填充属性视图角标 Display the database title on the block superscript https://github.com/siyuan-note/siyuan/issues/10545
@@ -316,7 +317,7 @@ func getNodeRefText0(node *ast.Node, maxLen int) string {
 	return ret
 }
 
-func GetBlockRefs(defID string) (refIDs, refTexts, defIDs []string) {
+func GetBlockRefs(defID string, isBacklink bool) (refIDs, refTexts, defIDs []string) {
 	refIDs = []string{}
 	refTexts = []string{}
 	defIDs = []string{}
@@ -332,6 +333,10 @@ func GetBlockRefs(defID string) (refIDs, refTexts, defIDs []string) {
 	} else {
 		defIDs = append(defIDs, defID)
 	}
+
+	if isBacklink {
+		buildBacklinkListItemRefs(&refIDs)
+	}
 	return
 }
 
@@ -548,3 +553,17 @@ func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string, isEmbedBlock bo
 	}
 	return
 }
+
+func buildBacklinkListItemRefs(refIDs *[]string) {
+	refBts := treenode.GetBlockTrees(*refIDs)
+	for i, refID := range *refIDs {
+		if bt := refBts[refID]; nil != bt {
+			if "p" == bt.Type {
+				if parent := treenode.GetBlockTree(bt.ParentID); nil != parent && "i" == parent.Type {
+					// 引用计数浮窗请求,需要按照反链逻辑组装 https://github.com/siyuan-note/siyuan/issues/6853
+					(*refIDs)[i] = parent.ID
+				}
+			}
+		}
+	}
+}

+ 0 - 8
kernel/model/file.go

@@ -634,14 +634,6 @@ func GetDoc(startID, endID, id string, index int, query string, queryTypes map[s
 		}
 	}
 
-	if isBacklink { // 引用计数浮窗请求,需要按照反链逻辑组装 https://github.com/siyuan-note/siyuan/issues/6853
-		if ast.NodeParagraph == node.Type {
-			if nil != node.Parent && ast.NodeListItem == node.Parent.Type {
-				node = node.Parent
-			}
-		}
-	}
-
 	located := false
 	isDoc := ast.NodeDocument == node.Type
 	isHeading := ast.NodeHeading == node.Type

+ 1 - 1
kernel/model/push_reload.go

@@ -157,7 +157,7 @@ func refreshRefCount(rootID, blockID string) {
 	for _, count := range refCounts {
 		rootRefCount += count
 	}
-	refIDs, _, _ := GetBlockRefs(blockID)
+	refIDs, _, _ := GetBlockRefs(blockID, false)
 	util.PushSetDefRefCount(rootID, blockID, refIDs, refCount, rootRefCount)
 }