mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-15 15:28:37 +08:00
🎨 Update the parent_id of blocks below a heading block when updating the heading block https://github.com/siyuan-note/siyuan/issues/14871
This commit is contained in:
parent
35ca2be3b5
commit
e321c639a7
@ -849,7 +849,7 @@ func buildBlockFromNode(n *ast.Node, tree *parse.Tree) (block *Block, attributes
|
||||
fcontent = NodeStaticContent(fc, nil, true, false, true)
|
||||
|
||||
parentID = n.Parent.ID
|
||||
if h := heading(n); nil != h { // 如果在标题块下方,则将标题块作为父节点
|
||||
if h := treenode.HeadingParent(n); nil != h { // 如果在标题块下方,则将标题块作为父节点
|
||||
parentID = h.ID
|
||||
}
|
||||
length = utf8.RuneCountInString(fcontent)
|
||||
@ -861,7 +861,7 @@ func buildBlockFromNode(n *ast.Node, tree *parse.Tree) (block *Block, attributes
|
||||
content = NodeStaticContent(n, nil, true, indexAssetPath, true)
|
||||
|
||||
parentID = n.Parent.ID
|
||||
if h := heading(n); nil != h {
|
||||
if h := treenode.HeadingParent(n); nil != h {
|
||||
parentID = h.ID
|
||||
}
|
||||
length = utf8.RuneCountInString(content)
|
||||
@ -945,26 +945,6 @@ func tagFromNode(node *ast.Node) (ret string) {
|
||||
return strings.TrimSpace(tagBuilder.String())
|
||||
}
|
||||
|
||||
func heading(node *ast.Node) *ast.Node {
|
||||
if nil == node {
|
||||
return nil
|
||||
}
|
||||
|
||||
currentLevel := 16
|
||||
if ast.NodeHeading == node.Type {
|
||||
currentLevel = node.HeadingLevel
|
||||
}
|
||||
|
||||
for prev := node.Previous; nil != prev; prev = prev.Previous {
|
||||
if ast.NodeHeading == prev.Type {
|
||||
if prev.HeadingLevel < currentLevel {
|
||||
return prev
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteByBoxTx(tx *sql.Tx, box string) (err error) {
|
||||
if err = deleteBlocksByBoxTx(tx, box); err != nil {
|
||||
return
|
||||
|
||||
@ -44,9 +44,14 @@ func NodeHash(node *ast.Node, tree *parse.Tree, luteEngine *lute.Lute) string {
|
||||
}
|
||||
hpath := tree.HPath
|
||||
data := tree.Box + tree.Path + hpath + string(ial) + md
|
||||
var parentID string
|
||||
if nil != node.Parent {
|
||||
data += node.Parent.ID
|
||||
parentID = node.Parent.ID
|
||||
}
|
||||
if h := HeadingParent(node); nil != h {
|
||||
parentID = h.ID
|
||||
}
|
||||
data += parentID
|
||||
return fmt.Sprintf("%x", sha256.Sum256(gulu.Str.ToBytes(data)))[:7]
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user