Skip to content

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

:art: Add two shortcuts for block navigation https://github.com/siyuan-note/siyuan/issues/11193

Danielcf187dddcefe
diff --git a/kernel/api/block.go b/kernel/api/block.go
index 37611ce15f..1e7ea07224 100644
--- a/kernel/api/block.go
+++ b/kernel/api/block.go
@@ -29,7 +29,7 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
-func getParentNextChildID(c *gin.Context) {
+func getBlockSiblingID(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
@@ -39,8 +39,11 @@ func getParentNextChildID(c *gin.Context) {
}
id := arg["id"].(string)
+ parent, previous, next := model.GetBlockSiblingID(id)
ret.Data = map[string]string{
- "id": model.GetParentNextChildID(id),
+ "parent": parent,
+ "next": next,
+ "previous": previous,
}
}
diff --git a/kernel/api/router.go b/kernel/api/router.go
index 0b6e89593c..6b5f530156 100644
--- a/kernel/api/router.go
+++ b/kernel/api/router.go
@@ -198,7 +198,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/block/getHeadingChildrenDOM", model.CheckAuth, getHeadingChildrenDOM)
ginServer.Handle("POST", "/api/block/swapBlockRef", model.CheckAuth, model.CheckReadonly, swapBlockRef)
ginServer.Handle("POST", "/api/block/transferBlockRef", model.CheckAuth, model.CheckReadonly, transferBlockRef)
- ginServer.Handle("POST", "/api/block/getParentNextChildID", model.CheckAuth, getParentNextChildID)
+ ginServer.Handle("POST", "/api/block/getBlockSiblingID", model.CheckAuth, getBlockSiblingID)
ginServer.Handle("POST", "/api/file/getFile", model.CheckAuth, getFile)
ginServer.Handle("POST", "/api/file/putFile", model.CheckAuth, model.CheckReadonly, putFile)
diff --git a/kernel/model/block.go b/kernel/model/block.go
index 2fe6e79935..1c37742803 100644
--- a/kernel/model/block.go
+++ b/kernel/model/block.go
@@ -114,33 +114,33 @@ type Path struct {
Created string `json:"created"` // 创建时间
}
-func GetParentNextChildID(id string) string {
+func GetBlockSiblingID(id string) (parent, previous, next string) {
tree, err := LoadTreeByBlockID(id)
if nil != err {
- return ""
+ return
}
node := treenode.GetNodeInTree(tree, id)
if nil == node {
- return ""
+ return
}
- for p := node.Parent; nil != p; p = p.Parent {
- if ast.NodeDocument == p.Type {
- if nil != node.Next {
- return node.Next.ID
- }
- return ""
- }
+ if !node.IsBlock() {
+ return
+ }
- for f := p.Next; nil != f; f = f.Next {
- // 遍历取下一个块级元素(比如跳过超级块 Close 节点)
- if f.IsBlock() {
- return f.ID
- }
- }
+ if nil != node.Parent && node.Parent.IsBlock() {
+ parent = node.Parent.ID
+ }
+
+ if nil != node.Previous && node.Previous.IsBlock() {
+ previous = node.Previous.ID
}
- return ""
+
+ if nil != node.Next && node.Next.IsBlock() {
+ next = node.Next.ID
+ }
+ return
}
func IsBlockFolded(id string) bool {