From 818d1746c0430e64cefc5b5baf5f94d0bdeb6e3c Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 16 Nov 2024 17:29:59 +0800 Subject: [PATCH] :art: Prevent parent move into child https://github.com/siyuan-note/siyuan/issues/13131 --- kernel/model/transaction.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index 3078bfb04..f16dfa013 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -358,6 +358,10 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) { return } + if isMovingParentIntoChild(srcNode, targetNode) { + return + } + for i := len(headingChildren) - 1; -1 < i; i-- { c := headingChildren[i] targetNode.InsertAfter(c) @@ -407,6 +411,10 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) { return } + if isMovingParentIntoChild(srcNode, targetNode) { + return + } + processed := false if ast.NodeSuperBlock == targetNode.Type { // 在布局节点后插入 @@ -474,6 +482,15 @@ func isMovingFoldHeadingIntoSelf(targetNode *ast.Node, headingChildren []*ast.No return false } +func isMovingParentIntoChild(srcNode, targetNode *ast.Node) bool { + for parent := targetNode.Parent; nil != parent; parent = parent.Parent { + if parent.ID == srcNode.ID { + return true + } + } + return false +} + func (tx *Transaction) doPrependInsert(operation *Operation) (ret *TxErr) { var err error block := treenode.GetBlockTree(operation.ParentID)