From 6dff64f24641806208761347f377b72cd7c0c09b Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 2 Apr 2024 15:11:02 +0800 Subject: [PATCH] :bug: Improve outline dnd https://github.com/siyuan-note/siyuan/issues/10828 --- kernel/model/outline.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/kernel/model/outline.go b/kernel/model/outline.go index 28e73a47b..a5a3247c3 100644 --- a/kernel/model/outline.go +++ b/kernel/model/outline.go @@ -40,11 +40,18 @@ func (tx *Transaction) doMoveOutlineHeading(operation *Operation) (ret *TxErr) { return &TxErr{code: TxErrCodeBlockNotFound, id: headingID} } + operation.RetData = tree.Root.ID + heading := treenode.GetNodeInTree(tree, headingID) if nil == heading { return &TxErr{code: TxErrCodeBlockNotFound, id: headingID} } + if ast.NodeDocument != heading.Parent.Type { + // 仅支持文档根节点下第一层标题,不支持容器块内标题 + return + } + headings := []*ast.Node{} ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus { if entering && ast.NodeHeading == n.Type && !n.ParentIs(ast.NodeBlockquote) { @@ -71,6 +78,11 @@ func (tx *Transaction) doMoveOutlineHeading(operation *Operation) (ret *TxErr) { return &TxErr{code: TxErrCodeBlockNotFound, id: previousID} } + if ast.NodeDocument != previousHeading.Parent.Type { + // 仅支持文档根节点下第一层标题,不支持容器块内标题 + return + } + targetNode := previousHeading previousHeadingChildren := treenode.HeadingChildren(previousHeading) if 0 < len(previousHeadingChildren) { @@ -102,6 +114,11 @@ func (tx *Transaction) doMoveOutlineHeading(operation *Operation) (ret *TxErr) { return &TxErr{code: TxErrCodeBlockNotFound, id: parentID} } + if ast.NodeDocument != parentHeading.Parent.Type { + // 仅支持文档根节点下第一层标题,不支持容器块内标题 + return + } + targetNode := parentHeading parentHeadingChildren := treenode.HeadingChildren(parentHeading) @@ -153,8 +170,6 @@ func (tx *Transaction) doMoveOutlineHeading(operation *Operation) (ret *TxErr) { if err = tx.writeTree(tree); nil != err { return } - - operation.RetData = tree.Root.ID return }