mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00: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
c1a301767d
commit
6c63bccd75
1 changed files with 42 additions and 28 deletions
|
|
@ -912,9 +912,7 @@ func (tx *Transaction) doDelete(operation *Operation) (ret *TxErr) {
|
||||||
node.Next.Unlink()
|
node.Next.Unlink()
|
||||||
}
|
}
|
||||||
|
|
||||||
next := node.Next
|
|
||||||
node.Unlink()
|
node.Unlink()
|
||||||
unfoldParentFoldedHeading(next)
|
|
||||||
|
|
||||||
if nil != parent && ast.NodeListItem == parent.Type && nil == parent.FirstChild {
|
if nil != parent && ast.NodeListItem == parent.Type && nil == parent.FirstChild {
|
||||||
needAppendEmptyListItem := true
|
needAppendEmptyListItem := true
|
||||||
|
|
@ -1279,7 +1277,8 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
||||||
}
|
}
|
||||||
node.InsertAfter(insertedNode)
|
node.InsertAfter(insertedNode)
|
||||||
|
|
||||||
unfoldParentFoldedHeading(insertedNode)
|
parentFoldedHeading := treenode.GetParentFoldedHeading(insertedNode)
|
||||||
|
unfoldHeading(parentFoldedHeading)
|
||||||
} else {
|
} else {
|
||||||
node = treenode.GetNodeInTree(tree, operation.ParentID)
|
node = treenode.GetNodeInTree(tree, operation.ParentID)
|
||||||
if nil == node {
|
if nil == node {
|
||||||
|
|
@ -1526,11 +1525,20 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
||||||
syncDelete2AvBlock(n, tree, tx)
|
syncDelete2AvBlock(n, tree, tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 替换为新节点
|
var needUnfoldParentHeading bool
|
||||||
|
if 0 < oldNode.HeadingLevel && (0 == updatedNode.HeadingLevel || oldNode.HeadingLevel < updatedNode.HeadingLevel) {
|
||||||
|
// 将不属于折叠标题的块移动到折叠标题下方,需要展开折叠标题
|
||||||
|
needUnfoldParentHeading = true
|
||||||
|
}
|
||||||
|
|
||||||
oldNode.InsertAfter(updatedNode)
|
oldNode.InsertAfter(updatedNode)
|
||||||
oldNode.Unlink()
|
oldNode.Unlink()
|
||||||
|
|
||||||
unfoldParentFoldedHeading(updatedNode)
|
if needUnfoldParentHeading {
|
||||||
|
parentFoldedHeading := treenode.GetParentFoldedHeading(updatedNode)
|
||||||
|
unfoldHeading(parentFoldedHeading)
|
||||||
|
}
|
||||||
|
|
||||||
createdUpdated(updatedNode)
|
createdUpdated(updatedNode)
|
||||||
tx.nodes[updatedNode.ID] = updatedNode
|
tx.nodes[updatedNode.ID] = updatedNode
|
||||||
if err = tx.writeTree(tree); err != nil {
|
if err = tx.writeTree(tree); err != nil {
|
||||||
|
|
@ -1561,9 +1569,12 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func unfoldParentFoldedHeading(node *ast.Node) {
|
func unfoldHeading(heading *ast.Node) {
|
||||||
if parentFoldedHeading := treenode.GetParentFoldedHeading(node); nil != parentFoldedHeading {
|
if nil == heading {
|
||||||
children := treenode.HeadingChildren(parentFoldedHeading)
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
children := treenode.HeadingChildren(heading)
|
||||||
for _, child := range children {
|
for _, child := range children {
|
||||||
ast.Walk(child, func(n *ast.Node, entering bool) ast.WalkStatus {
|
ast.Walk(child, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
if !entering || !n.IsBlock() {
|
if !entering || !n.IsBlock() {
|
||||||
|
|
@ -1575,16 +1586,19 @@ func unfoldParentFoldedHeading(node *ast.Node) {
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
parentFoldedHeading.RemoveIALAttr("fold")
|
heading.RemoveIALAttr("fold")
|
||||||
parentFoldedHeading.RemoveIALAttr("heading-fold")
|
heading.RemoveIALAttr("heading-fold")
|
||||||
|
|
||||||
evt := util.NewCmdResult("transactions", 0, util.PushModeBroadcast)
|
evt := util.NewCmdResult("transactions", 0, util.PushModeBroadcast)
|
||||||
evt.Data = []*Transaction{{
|
evt.Data = []*Transaction{{
|
||||||
DoOperations: []*Operation{{Action: "unfoldHeading", ID: parentFoldedHeading.ID}},
|
DoOperations: []*Operation{{Action: "unfoldHeading", ID: heading.ID}},
|
||||||
UndoOperations: []*Operation{{Action: "foldHeading", ID: parentFoldedHeading.ID}},
|
UndoOperations: []*Operation{{Action: "foldHeading", ID: heading.ID}},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
util.PushEvent(evt)
|
util.PushEvent(evt)
|
||||||
}
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRefDefIDs(node *ast.Node) (refDefIDs []string) {
|
func getRefDefIDs(node *ast.Node) (refDefIDs []string) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue