mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🐛 The parent block field of the blocks under the heading block is calculated incorrectly https://github.com/siyuan-note/siyuan/issues/9869
This commit is contained in:
parent
f8a5ca0aa6
commit
1864d0e4a6
2 changed files with 24 additions and 3 deletions
|
|
@ -1048,6 +1048,15 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
||||||
treenode.MoveFoldHeading(updatedNode, oldNode)
|
treenode.MoveFoldHeading(updatedNode, oldNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ast.NodeHeading == oldNode.Type && ast.NodeHeading != updatedNode.Type {
|
||||||
|
// 将标题块更新为非标题块时需要更新下方块的 parent id
|
||||||
|
children := treenode.HeadingChildren(oldNode)
|
||||||
|
updated := time.Now().Format("20060102150405")
|
||||||
|
for _, child := range children {
|
||||||
|
child.SetIALAttr("updated", updated)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cache.PutBlockIAL(updatedNode.ID, parse.IAL2Map(updatedNode.KramdownIAL))
|
cache.PutBlockIAL(updatedNode.ID, parse.IAL2Map(updatedNode.KramdownIAL))
|
||||||
|
|
||||||
// 替换为新节点
|
// 替换为新节点
|
||||||
|
|
@ -1055,6 +1064,16 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
||||||
oldNode.Unlink()
|
oldNode.Unlink()
|
||||||
|
|
||||||
createdUpdated(updatedNode)
|
createdUpdated(updatedNode)
|
||||||
|
if ast.NodeHeading != oldNode.Type && ast.NodeHeading == updatedNode.Type {
|
||||||
|
// 将非标题块更新为标题块时需要更新下方块的 parent id
|
||||||
|
// The parent block field of the blocks under the heading block is calculated incorrectly https://github.com/siyuan-note/siyuan/issues/9869
|
||||||
|
children := treenode.HeadingChildren(updatedNode)
|
||||||
|
updated := updatedNode.IALAttr("updated")
|
||||||
|
for _, child := range children {
|
||||||
|
child.SetIALAttr("updated", updated)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tx.nodes[updatedNode.ID] = updatedNode
|
tx.nodes[updatedNode.ID] = updatedNode
|
||||||
if err = tx.writeTree(tree); nil != err {
|
if err = tx.writeTree(tree); nil != err {
|
||||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: id}
|
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: id}
|
||||||
|
|
|
||||||
|
|
@ -810,8 +810,7 @@ func buildBlockFromNode(n *ast.Node, tree *parse.Tree) (block *Block, attributes
|
||||||
fcontent = treenode.NodeStaticContent(fc, nil, true, false, true)
|
fcontent = treenode.NodeStaticContent(fc, nil, true, false, true)
|
||||||
|
|
||||||
parentID = n.Parent.ID
|
parentID = n.Parent.ID
|
||||||
// 将标题块作为父节点
|
if h := heading(n); nil != h { // 如果在标题块下方,则将标题块作为父节点
|
||||||
if h := heading(n); nil != h {
|
|
||||||
parentID = h.ID
|
parentID = h.ID
|
||||||
}
|
}
|
||||||
length = utf8.RuneCountInString(fcontent)
|
length = utf8.RuneCountInString(fcontent)
|
||||||
|
|
@ -823,7 +822,6 @@ func buildBlockFromNode(n *ast.Node, tree *parse.Tree) (block *Block, attributes
|
||||||
content = treenode.NodeStaticContent(n, nil, true, indexAssetPath, true)
|
content = treenode.NodeStaticContent(n, nil, true, indexAssetPath, true)
|
||||||
|
|
||||||
parentID = n.Parent.ID
|
parentID = n.Parent.ID
|
||||||
// 将标题块作为父节点
|
|
||||||
if h := heading(n); nil != h {
|
if h := heading(n); nil != h {
|
||||||
parentID = h.ID
|
parentID = h.ID
|
||||||
}
|
}
|
||||||
|
|
@ -909,6 +907,10 @@ func tagFromNode(node *ast.Node) (ret string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func heading(node *ast.Node) *ast.Node {
|
func heading(node *ast.Node) *ast.Node {
|
||||||
|
if nil == node {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
currentLevel := 16
|
currentLevel := 16
|
||||||
if ast.NodeHeading == node.Type {
|
if ast.NodeHeading == node.Type {
|
||||||
currentLevel = node.HeadingLevel
|
currentLevel = node.HeadingLevel
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue