Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2024-04-30 21:44:17 +08:00
commit 733014b266
3 changed files with 24 additions and 21 deletions

View file

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

View file

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

View file

@ -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 ""
}
for f := p.Next; nil != f; f = f.Next {
// 遍历取下一个块级元素(比如跳过超级块 Close 节点)
if f.IsBlock() {
return f.ID
}
}
if !node.IsBlock() {
return
}
return ""
if nil != node.Parent && node.Parent.IsBlock() {
parent = node.Parent.ID
}
if nil != node.Previous && node.Previous.IsBlock() {
previous = node.Previous.ID
}
if nil != node.Next && node.Next.IsBlock() {
next = node.Next.ID
}
return
}
func IsBlockFolded(id string) bool {