Skip to content

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

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

Daniele24ff7d8c4e2
diff --git a/kernel/api/block_op.go b/kernel/api/block_op.go
index 97261bee3f..c88bdb50ec 100644
--- a/kernel/api/block_op.go
+++ b/kernel/api/block_op.go
@@ -319,6 +319,13 @@ func moveBlock(c *gin.Context) {
return
}
+ currentBt := treenode.GetBlockTree(id)
+ if nil == currentBt {
+ ret.Code = -1
+ ret.Msg = "block not found [id=" + id + "]"
+ return
+ }
+
var parentID, previousID string
if nil != arg["parentID"] {
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{
{
DoOperations: []*model.Operation{
@@ -356,8 +376,10 @@ func moveBlock(c *gin.Context) {
model.PerformTransactions(&transactions)
model.FlushTxQueue()
- ret.Data = transactions
- broadcastTransactions(transactions)
+ model.ReloadProtyle(currentBt.RootID)
+ if currentBt.RootID != targetBt.RootID {
+ model.ReloadProtyle(targetBt.RootID)
+ }
}
func appendBlock(c *gin.Context) {