This commit is contained in:
Liang Ding 2022-06-19 17:01:21 +08:00
parent eac168e0e0
commit 501b0b1864
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
6 changed files with 45 additions and 29 deletions

View file

@ -142,7 +142,7 @@ func getBlockRendered(id string, headingMode int) (ret *Block) {
if ast.NodeHeading == n.Type {
if "1" == n.IALAttr("fold") {
children := treenode.FoldedHeadingChildren(n)
children := treenode.HeadingChildren(n)
for _, c := range children {
unlinks = append(unlinks, c)
}

View file

@ -662,7 +662,7 @@ func loadNodesByMode(node *ast.Node, inputIndex, mode, size int, isDoc, isHeadin
if ast.NodeHeading == node.Type {
// 标题展开时进行动态加载导致重复内容 https://github.com/siyuan-note/siyuan/issues/4671
// 这里要考虑折叠标题是最后一个块的情况
if children := treenode.FoldedHeadingChildren(node); 0 < len(children) {
if children := treenode.HeadingChildren(node); 0 < len(children) {
next = children[len(children)-1].Next
}
}
@ -679,7 +679,7 @@ func loadNodesByMode(node *ast.Node, inputIndex, mode, size int, isDoc, isHeadin
nodes = append(nodes, node)
if isDoc {
for n := node.Next; nil != n; n = n.Next {
if "1" == n.IALAttr("heading-fold") {
if treenode.IsInFoldedHeading(n, nil) {
continue
}
nodes = append(nodes, n)
@ -695,7 +695,7 @@ func loadNodesByMode(node *ast.Node, inputIndex, mode, size int, isDoc, isHeadin
} else if isHeading {
level := node.HeadingLevel
for n := node.Next; nil != n; n = n.Next {
if "1" == n.IALAttr("heading-fold") {
if treenode.IsInFoldedHeading(n, node) {
// 大纲点击折叠标题跳转聚焦 https://github.com/siyuan-note/siyuan/issues/4920
// 多级标题折叠后上级块引浮窗中未折叠 https://github.com/siyuan-note/siyuan/issues/4997
continue
@ -720,7 +720,7 @@ func loadNodesByMode(node *ast.Node, inputIndex, mode, size int, isDoc, isHeadin
}
case 4: // Ctrl+End 跳转到末尾后向上加载
for n := node; nil != n; n = n.Previous {
if "1" == n.IALAttr("heading-fold") {
if treenode.IsInFoldedHeading(n, nil) {
continue
}
nodes = append([]*ast.Node{n}, nodes...)
@ -736,7 +736,7 @@ func loadNodesByMode(node *ast.Node, inputIndex, mode, size int, isDoc, isHeadin
eof = true
case 1: // 向上加载
for n := node.Previous; /* 从上一个节点开始加载 */ nil != n; n = n.Previous {
if "1" == n.IALAttr("heading-fold") {
if treenode.IsInFoldedHeading(n, nil) {
continue
}
nodes = append([]*ast.Node{n}, nodes...)
@ -752,7 +752,7 @@ func loadNodesByMode(node *ast.Node, inputIndex, mode, size int, isDoc, isHeadin
eof = nil == node.Previous
case 2: // 向下加载
for n := node.Next; /* 从下一个节点开始加载 */ nil != n; n = n.Next {
if "1" == n.IALAttr("heading-fold") {
if treenode.IsInFoldedHeading(n, node) {
continue
}
nodes = append(nodes, n)
@ -767,7 +767,7 @@ func loadNodesByMode(node *ast.Node, inputIndex, mode, size int, isDoc, isHeadin
}
case 3: // 上下都加载
for n := node; nil != n; n = n.Previous {
if "1" == n.IALAttr("heading-fold") {
if treenode.IsInFoldedHeading(n, nil) {
continue
}
nodes = append([]*ast.Node{n}, nodes...)
@ -793,7 +793,7 @@ func loadNodesByMode(node *ast.Node, inputIndex, mode, size int, isDoc, isHeadin
}
count = 0
for n := node.Next; nil != n; n = n.Next {
if "1" == n.IALAttr("heading-fold") {
if treenode.IsInFoldedHeading(n, nil) {
continue
}
nodes = append(nodes, n)

View file

@ -48,7 +48,7 @@ func (tx *Transaction) doFoldHeading(operation *Operation) (ret *TxErr) {
children := treenode.HeadingChildren(heading)
for _, child := range children {
childrenIDs = append(childrenIDs, child.ID)
child.RemoveIALAttr("fold")
child.SetIALAttr("fold", "1")
child.SetIALAttr("heading-fold", "1")
}
heading.SetIALAttr("fold", "1")
@ -79,12 +79,13 @@ func (tx *Transaction) doUnfoldHeading(operation *Operation) (ret *TxErr) {
return &TxErr{code: TxErrCodeBlockNotFound, id: headingID}
}
children := treenode.FoldedHeadingChildren(heading)
children := treenode.HeadingChildren(heading)
for _, child := range children {
child.RemoveIALAttr("heading-fold")
child.RemoveIALAttr("fold")
}
heading.RemoveIALAttr("fold")
heading.RemoveIALAttr("heading-fold")
if err = tx.writeTree(tree); nil != err {
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: headingID}
}
@ -263,7 +264,7 @@ func Heading2Doc(srcHeadingID, targetBoxID, targetPath string) (srcRootBlockID,
}
// 折叠标题转换为文档时需要自动展开下方块 https://github.com/siyuan-note/siyuan/issues/2947
children := treenode.FoldedHeadingChildren(headingNode)
children := treenode.HeadingChildren(headingNode)
for _, child := range children {
child.RemoveIALAttr("heading-fold")
child.RemoveIALAttr("fold")

View file

@ -33,6 +33,22 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
func UploadSnapshot(id string) (err error) {
if 1 > len(Conf.Repo.Key) {
err = errors.New(Conf.Language(26))
return
}
repo, err := dejavu.NewRepo(util.DataDir, util.RepoDir, Conf.Repo.Key)
if nil != err {
util.LogErrorf("init repo failed: %s", err)
return
}
_ = repo
return
}
func GetRepoIndexLogs(page int) (logs []*dejavu.Log, pageCount, totalCount int, err error) {
if 1 > len(Conf.Repo.Key) {
err = errors.New(Conf.Language(26))

View file

@ -291,7 +291,7 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
var headingChildren []*ast.Node
if isMovingFoldHeading := ast.NodeHeading == srcNode.Type && "1" == srcNode.IALAttr("fold"); isMovingFoldHeading {
headingChildren = treenode.FoldedHeadingChildren(srcNode)
headingChildren = treenode.HeadingChildren(srcNode)
}
var srcEmptyList *ast.Node
if ast.NodeListItem == srcNode.Type && srcNode.Parent.FirstChild == srcNode && srcNode.Parent.LastChild == srcNode {
@ -324,7 +324,7 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
}
if ast.NodeHeading == targetNode.Type && "1" == targetNode.IALAttr("fold") {
targetChildren := treenode.FoldedHeadingChildren(targetNode)
targetChildren := treenode.HeadingChildren(targetNode)
if l := len(targetChildren); 0 < l {
targetNode = targetChildren[l-1]
}
@ -611,7 +611,7 @@ func (tx *Transaction) doAppend(operation *Operation) (ret *TxErr) {
var headingChildren []*ast.Node
if isMovingFoldHeading := ast.NodeHeading == srcNode.Type && "1" == srcNode.IALAttr("fold"); isMovingFoldHeading {
headingChildren = treenode.FoldedHeadingChildren(srcNode)
headingChildren = treenode.HeadingChildren(srcNode)
}
var srcEmptyList, targetNewList *ast.Node
if ast.NodeListItem == srcNode.Type {
@ -910,7 +910,7 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
}
if ast.NodeHeading == node.Type && "1" == node.IALAttr("fold") {
children := treenode.FoldedHeadingChildren(node)
children := treenode.HeadingChildren(node)
if l := len(children); 0 < l {
node = children[l-1]
}

View file

@ -30,7 +30,7 @@ func MoveFoldHeading(updateNode, oldNode *ast.Node) {
}
if ast.NodeHeading == n.Type && "1" == n.IALAttr("fold") {
children := FoldedHeadingChildren(n)
children := HeadingChildren(n)
foldHeadings[n.ID] = children
}
return ast.WalkContinue
@ -57,20 +57,19 @@ func MoveFoldHeading(updateNode, oldNode *ast.Node) {
return
}
func FoldedHeadingChildren(heading *ast.Node) (ret []*ast.Node) {
children := HeadingChildren(heading)
if 1 > len(children) {
return
func IsInFoldedHeading(node, currentHeading *ast.Node) bool {
heading := HeadingParent(node)
if nil == heading {
return false
}
for _, c := range children {
if "1" == c.IALAttr("heading-fold") {
ret = append(ret, c)
} else {
break
}
if "1" == heading.IALAttr("heading-fold") || "1" == heading.IALAttr("fold") {
return true
}
return
if heading == currentHeading {
// node 就在当前标题层级下的话不递归继续查询,直接返回不折叠
return false
}
return IsInFoldedHeading(heading, currentHeading)
}
func HeadingChildren(heading *ast.Node) (ret []*ast.Node) {