mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 Improve fold heading editing https://github.com/siyuan-note/siyuan/issues/15989
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
ae80dc94d5
commit
aad5b61a23
1 changed files with 28 additions and 8 deletions
|
|
@ -1527,14 +1527,7 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
|||
|
||||
oldParentFoldedHeading := treenode.GetParentFoldedHeading(oldNode)
|
||||
// 将原先折叠标题下的块提升为与折叠标题同级或更高一级的标题时,需要在折叠标题后插入该提升后的标题块(只需要推送界面插入)
|
||||
if needInsertAfterParentHeading := nil != oldParentFoldedHeading && 0 != updatedNode.HeadingLevel && updatedNode.HeadingLevel <= oldParentFoldedHeading.HeadingLevel; needInsertAfterParentHeading {
|
||||
evt := util.NewCmdResult("transactions", 0, util.PushModeBroadcast)
|
||||
evt.Data = []*Transaction{{
|
||||
DoOperations: []*Operation{{Action: "insert", ID: updatedNode.ID, PreviousID: oldParentFoldedHeading.ID, Data: data}},
|
||||
UndoOperations: []*Operation{{Action: "delete", ID: updatedNode.ID}},
|
||||
}}
|
||||
util.PushEvent(evt)
|
||||
}
|
||||
needInsertAfterParentHeading := nil != oldParentFoldedHeading && 0 != updatedNode.HeadingLevel && updatedNode.HeadingLevel <= oldParentFoldedHeading.HeadingLevel
|
||||
|
||||
oldNode.InsertAfter(updatedNode)
|
||||
oldNode.Unlink()
|
||||
|
|
@ -1546,6 +1539,33 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
}
|
||||
|
||||
if needInsertAfterParentHeading {
|
||||
insertDom := data
|
||||
if 2 == len(tx.DoOperations) && "foldHeading" == tx.DoOperations[1].Action {
|
||||
children := treenode.HeadingChildren(updatedNode)
|
||||
for _, child := range children {
|
||||
ast.Walk(child, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering || !n.IsBlock() {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
n.SetIALAttr("fold", "1")
|
||||
n.SetIALAttr("heading-fold", "1")
|
||||
return ast.WalkContinue
|
||||
})
|
||||
}
|
||||
updatedNode.SetIALAttr("fold", "1")
|
||||
insertDom = tx.luteEngine.RenderNodeBlockDOM(updatedNode)
|
||||
}
|
||||
|
||||
evt := util.NewCmdResult("transactions", 0, util.PushModeBroadcast)
|
||||
evt.Data = []*Transaction{{
|
||||
DoOperations: []*Operation{{Action: "insert", ID: updatedNode.ID, PreviousID: oldParentFoldedHeading.ID, Data: insertDom}},
|
||||
UndoOperations: []*Operation{{Action: "delete", ID: updatedNode.ID}},
|
||||
}}
|
||||
util.PushEvent(evt)
|
||||
}
|
||||
|
||||
createdUpdated(updatedNode)
|
||||
tx.nodes[updatedNode.ID] = updatedNode
|
||||
if err = tx.writeTree(tree); err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue