From b3edfec60eed6ac902bb54a373831c694075ba9d Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 26 Jan 2023 01:16:01 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E6=8A=98=E5=8F=A0=E6=A0=87=E9=A2=98?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=88=B0=E4=B8=8B=E6=96=B9=E5=90=8E=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E7=8A=B6=E6=80=81=E5=BC=82=E5=B8=B8=E5=B9=B6=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E6=95=B0=E6=8D=AE=E4=B8=A2=E5=A4=B1=20Fix=20https://g?= =?UTF-8?q?ithub.com/siyuan-note/siyuan/issues/7163?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/transaction.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index a047fe519..9eaceedea 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -311,11 +311,8 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) { } } - for _, headingChild := range headingChildren { - if headingChild.ID == targetNode.ID { - // 不能将折叠标题移动到自己下方节点的前或后 https://github.com/siyuan-note/siyuan/issues/7163 - return - } + if isMovingFoldHeadingIntoSelf(targetNode, headingChildren) { + return } for i := len(headingChildren) - 1; -1 < i; i-- { @@ -360,11 +357,8 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) { return &TxErr{code: TxErrCodeBlockNotFound, id: targetParentID} } - for _, headingChild := range headingChildren { - if headingChild.ID == targetNode.ID { - // 不能将折叠标题移动到自己下方节点的前或后 https://github.com/siyuan-note/siyuan/issues/7163 - return - } + if isMovingFoldHeadingIntoSelf(targetNode, headingChildren) { + return } processed := false @@ -421,6 +415,16 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) { return } +func isMovingFoldHeadingIntoSelf(targetNode *ast.Node, headingChildren []*ast.Node) bool { + for _, headingChild := range headingChildren { + if headingChild.ID == targetNode.ID { + // 不能将折叠标题移动到自己下方节点的前或后 https://github.com/siyuan-note/siyuan/issues/7163 + return true + } + } + return false +} + func (tx *Transaction) doPrependInsert(operation *Operation) (ret *TxErr) { var err error block := treenode.GetBlockTree(operation.ParentID)