🧑‍💻 Improve editor refresh for kernel API /api/block/moveBlock https://github.com/siyuan-note/siyuan/issues/14559

This commit is contained in:
Daniel 2025-04-13 18:36:25 +08:00
parent 87709cd5a1
commit e24ff7d8c4
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -319,6 +319,13 @@ func moveBlock(c *gin.Context) {
return return
} }
currentBt := treenode.GetBlockTree(id)
if nil == currentBt {
ret.Code = -1
ret.Msg = "block not found [id=" + id + "]"
return
}
var parentID, previousID string var parentID, previousID string
if nil != arg["parentID"] { if nil != arg["parentID"] {
parentID = arg["parentID"].(string) parentID = arg["parentID"].(string)
@ -340,6 +347,19 @@ func moveBlock(c *gin.Context) {
} }
} }
var targetBt *treenode.BlockTree
if "" != previousID {
targetBt = treenode.GetBlockTree(previousID)
} else if "" != parentID {
targetBt = treenode.GetBlockTree(parentID)
}
if nil == targetBt {
ret.Code = -1
ret.Msg = "target block not found [id=" + parentID + "]"
return
}
transactions := []*model.Transaction{ transactions := []*model.Transaction{
{ {
DoOperations: []*model.Operation{ DoOperations: []*model.Operation{
@ -356,8 +376,10 @@ func moveBlock(c *gin.Context) {
model.PerformTransactions(&transactions) model.PerformTransactions(&transactions)
model.FlushTxQueue() model.FlushTxQueue()
ret.Data = transactions model.ReloadProtyle(currentBt.RootID)
broadcastTransactions(transactions) if currentBt.RootID != targetBt.RootID {
model.ReloadProtyle(targetBt.RootID)
}
} }
func appendBlock(c *gin.Context) { func appendBlock(c *gin.Context) {