Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: 块滚动条跟随滚动 https://github.com/siyuan-note/siyuan/issues/4612

Liang Ding420693197d04
diff --git a/kernel/api/block.go b/kernel/api/block.go
index 611e2c0ac5..8488eaa8d6 100644
--- a/kernel/api/block.go
+++ b/kernel/api/block.go
@@ -321,6 +321,20 @@ func getBlockBreadcrumb(c *gin.Context) {
ret.Data = blockPath
}
+func getBlockIndex(c *gin.Context) {
+ ret := gulu.Ret.NewResult()
+ defer c.JSON(http.StatusOK, ret)
+
+ arg, ok := util.JsonArg(c, ret)
+ if !ok {
+ return
+ }
+
+ id := arg["id"].(string)
+ index := model.GetBlockIndex(id)
+ ret.Data = index
+}
+
func getBlockInfo(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
diff --git a/kernel/api/router.go b/kernel/api/router.go
index e978d3afbe..4b5ec5f658 100644
--- a/kernel/api/router.go
+++ b/kernel/api/router.go
@@ -131,6 +131,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/block/getBlockDOM", model.CheckAuth, getBlockDOM)
ginServer.Handle("POST", "/api/block/getBlockKramdown", model.CheckAuth, getBlockKramdown)
ginServer.Handle("POST", "/api/block/getBlockBreadcrumb", model.CheckAuth, getBlockBreadcrumb)
+ ginServer.Handle("POST", "/api/block/getBlockIndex", model.CheckAuth, getBlockIndex)
ginServer.Handle("POST", "/api/block/getRefIDs", model.CheckAuth, getRefIDs)
ginServer.Handle("POST", "/api/block/getRefIDsByFileAnnotationID", model.CheckAuth, getRefIDsByFileAnnotationID)
ginServer.Handle("POST", "/api/block/getBlockDefIDsByRefText", model.CheckAuth, getBlockDefIDsByRefText)
diff --git a/kernel/model/blockinfo.go b/kernel/model/blockinfo.go
index 0d2a4a6694..af20d8e511 100644
--- a/kernel/model/blockinfo.go
+++ b/kernel/model/blockinfo.go
@@ -153,6 +153,34 @@ func GetBlockDefIDsByRefText(refText string, excludeIDs []string) (ret []string)
return
}
+func GetBlockIndex(id string) (ret int) {
+ tree, _ := loadTreeByBlockID(id)
+ if nil == tree {
+ return
+ }
+ node := treenode.GetNodeInTree(tree, id)
+ if nil == node {
+ return
+ }
+
+ ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
+ if !entering {
+ return ast.WalkContinue
+ }
+
+ if !n.IsChildBlockOf(tree.Root, 1) {
+ return ast.WalkContinue
+ }
+
+ ret++
+ if node == n {
+ return ast.WalkStop
+ }
+ return ast.WalkContinue
+ })
+ return
+}
+
type BlockPath struct {
ID string `json:"id"`
Name string `json:"name"`