mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 Improve fold heading editing https://github.com/siyuan-note/siyuan/issues/15848
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
36a31c0503
commit
f6f58a0719
2 changed files with 28 additions and 47 deletions
|
|
@ -906,30 +906,16 @@ func (tx *Transaction) doDelete(operation *Operation) (ret *TxErr) {
|
||||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, defID)
|
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, defID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if parentFoldedHeading := treenode.GetParentFoldedHeading(node); nil != parentFoldedHeading {
|
|
||||||
children := treenode.HeadingChildren(parentFoldedHeading)
|
|
||||||
for _, child := range children {
|
|
||||||
ast.Walk(child, func(n *ast.Node, entering bool) ast.WalkStatus {
|
|
||||||
if !entering || !n.IsBlock() {
|
|
||||||
return ast.WalkContinue
|
|
||||||
}
|
|
||||||
|
|
||||||
n.RemoveIALAttr("fold")
|
|
||||||
n.RemoveIALAttr("heading-fold")
|
|
||||||
return ast.WalkContinue
|
|
||||||
})
|
|
||||||
}
|
|
||||||
parentFoldedHeading.RemoveIALAttr("fold")
|
|
||||||
parentFoldedHeading.RemoveIALAttr("heading-fold")
|
|
||||||
}
|
|
||||||
|
|
||||||
parent := node.Parent
|
parent := node.Parent
|
||||||
if nil != node.Next && ast.NodeKramdownBlockIAL == node.Next.Type && bytes.Contains(node.Next.Tokens, []byte(node.ID)) {
|
if nil != node.Next && ast.NodeKramdownBlockIAL == node.Next.Type && bytes.Contains(node.Next.Tokens, []byte(node.ID)) {
|
||||||
// 列表块撤销状态异常 https://github.com/siyuan-note/siyuan/issues/3985
|
// 列表块撤销状态异常 https://github.com/siyuan-note/siyuan/issues/3985
|
||||||
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
|
||||||
for _, op := range tx.DoOperations {
|
for _, op := range tx.DoOperations {
|
||||||
|
|
@ -1293,19 +1279,7 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
||||||
}
|
}
|
||||||
node.InsertAfter(insertedNode)
|
node.InsertAfter(insertedNode)
|
||||||
|
|
||||||
if parentFoldedHeading := treenode.GetParentFoldedHeading(insertedNode); nil != parentFoldedHeading {
|
unfoldParentFoldedHeading(insertedNode)
|
||||||
ast.Walk(insertedNode, func(n *ast.Node, entering bool) ast.WalkStatus {
|
|
||||||
if !entering || !n.IsBlock() {
|
|
||||||
return ast.WalkContinue
|
|
||||||
}
|
|
||||||
|
|
||||||
n.RemoveIALAttr("fold")
|
|
||||||
n.RemoveIALAttr("heading-fold")
|
|
||||||
return ast.WalkContinue
|
|
||||||
})
|
|
||||||
parentFoldedHeading.RemoveIALAttr("fold")
|
|
||||||
parentFoldedHeading.RemoveIALAttr("heading-fold")
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
node = treenode.GetNodeInTree(tree, operation.ParentID)
|
node = treenode.GetNodeInTree(tree, operation.ParentID)
|
||||||
if nil == node {
|
if nil == node {
|
||||||
|
|
@ -1556,23 +1530,7 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
||||||
oldNode.InsertAfter(updatedNode)
|
oldNode.InsertAfter(updatedNode)
|
||||||
oldNode.Unlink()
|
oldNode.Unlink()
|
||||||
|
|
||||||
if parentFoldedHeading := treenode.GetParentFoldedHeading(updatedNode); nil != parentFoldedHeading {
|
unfoldParentFoldedHeading(updatedNode)
|
||||||
children := treenode.HeadingChildren(parentFoldedHeading)
|
|
||||||
for _, child := range children {
|
|
||||||
ast.Walk(child, func(n *ast.Node, entering bool) ast.WalkStatus {
|
|
||||||
if !entering || !n.IsBlock() {
|
|
||||||
return ast.WalkContinue
|
|
||||||
}
|
|
||||||
|
|
||||||
n.RemoveIALAttr("fold")
|
|
||||||
n.RemoveIALAttr("heading-fold")
|
|
||||||
return ast.WalkContinue
|
|
||||||
})
|
|
||||||
}
|
|
||||||
parentFoldedHeading.RemoveIALAttr("fold")
|
|
||||||
parentFoldedHeading.RemoveIALAttr("heading-fold")
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
||||||
|
|
@ -1603,6 +1561,25 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func unfoldParentFoldedHeading(node *ast.Node) {
|
||||||
|
if parentFoldedHeading := treenode.GetParentFoldedHeading(node); nil != parentFoldedHeading {
|
||||||
|
children := treenode.HeadingChildren(parentFoldedHeading)
|
||||||
|
for _, child := range children {
|
||||||
|
ast.Walk(child, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
|
if !entering || !n.IsBlock() {
|
||||||
|
return ast.WalkContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
n.RemoveIALAttr("fold")
|
||||||
|
n.RemoveIALAttr("heading-fold")
|
||||||
|
return ast.WalkContinue
|
||||||
|
})
|
||||||
|
}
|
||||||
|
parentFoldedHeading.RemoveIALAttr("fold")
|
||||||
|
parentFoldedHeading.RemoveIALAttr("heading-fold")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getRefDefIDs(node *ast.Node) (refDefIDs []string) {
|
func getRefDefIDs(node *ast.Node) (refDefIDs []string) {
|
||||||
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
if !entering {
|
if !entering {
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,10 @@ func GetHeadingFold(nodes []*ast.Node) (ret []*ast.Node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetParentFoldedHeading(node *ast.Node) (parentFoldedHeading *ast.Node) {
|
func GetParentFoldedHeading(node *ast.Node) (parentFoldedHeading *ast.Node) {
|
||||||
|
if nil == node {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
currentLevel := 7
|
currentLevel := 7
|
||||||
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