This commit is contained in:
Daniel 2024-04-02 15:11:02 +08:00
parent f5b7def958
commit 6dff64f246
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -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
}