mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🐛 The insertion position is wrong after converting the list to paragraph block in the floating window https://github.com/siyuan-note/siyuan/issues/15396
This commit is contained in:
parent
27f412658b
commit
be684aee76
3 changed files with 62 additions and 0 deletions
|
|
@ -86,6 +86,31 @@ func getBlockSiblingID(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getBlockIDs(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)
|
||||||
|
parentID, previousID, nextID, err := model.GetBlockIDs(id)
|
||||||
|
if nil != err {
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = err.Error()
|
||||||
|
ret.Data = map[string]interface{}{"closeTimeout": 7000}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.Data = map[string]string{
|
||||||
|
"parentID": parentID,
|
||||||
|
"previousID": previousID,
|
||||||
|
"nextID": nextID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func transferBlockRef(c *gin.Context) {
|
func transferBlockRef(c *gin.Context) {
|
||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
defer c.JSON(http.StatusOK, ret)
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
|
||||||
|
|
@ -217,6 +217,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
||||||
ginServer.Handle("POST", "/api/block/swapBlockRef", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, swapBlockRef)
|
ginServer.Handle("POST", "/api/block/swapBlockRef", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, swapBlockRef)
|
||||||
ginServer.Handle("POST", "/api/block/transferBlockRef", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, transferBlockRef)
|
ginServer.Handle("POST", "/api/block/transferBlockRef", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, transferBlockRef)
|
||||||
ginServer.Handle("POST", "/api/block/getBlockSiblingID", model.CheckAuth, getBlockSiblingID)
|
ginServer.Handle("POST", "/api/block/getBlockSiblingID", model.CheckAuth, getBlockSiblingID)
|
||||||
|
ginServer.Handle("POST", "/api/block/getBlockIDs", model.CheckAuth, getBlockIDs)
|
||||||
ginServer.Handle("POST", "/api/block/getBlockTreeInfos", model.CheckAuth, getBlockTreeInfos)
|
ginServer.Handle("POST", "/api/block/getBlockTreeInfos", model.CheckAuth, getBlockTreeInfos)
|
||||||
ginServer.Handle("POST", "/api/block/checkBlockRef", model.CheckAuth, checkBlockRef)
|
ginServer.Handle("POST", "/api/block/checkBlockRef", model.CheckAuth, checkBlockRef)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -280,6 +280,42 @@ func GetBlockSiblingID(id string) (parent, previous, next string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetBlockIDs(id string) (parentID, previousID, nextID string, err error) {
|
||||||
|
tree, err := LoadTreeByBlockID(id)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
node := treenode.GetNodeInTree(tree, id)
|
||||||
|
if nil == node {
|
||||||
|
err = ErrBlockNotFound
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if nil != node.Parent {
|
||||||
|
parentID = node.Parent.ID
|
||||||
|
}
|
||||||
|
if nil != node.Previous {
|
||||||
|
previous := node.Previous
|
||||||
|
if ast.NodeKramdownBlockIAL == previous.Type {
|
||||||
|
previous = previous.Previous
|
||||||
|
}
|
||||||
|
if nil != previous {
|
||||||
|
previousID = previous.ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if nil != node.Next {
|
||||||
|
next := node.Next
|
||||||
|
if ast.NodeKramdownBlockIAL == next.Type {
|
||||||
|
next = next.Next
|
||||||
|
}
|
||||||
|
if nil != next {
|
||||||
|
nextID = next.ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func GetUnfoldedParentID(id string) (parentID string) {
|
func GetUnfoldedParentID(id string) (parentID string) {
|
||||||
tree, err := LoadTreeByBlockID(id)
|
tree, err := LoadTreeByBlockID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue