From 501b0b1864685b7439230c0d566ac65978504a36 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 19 Jun 2022 17:01:21 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E6=8A=98=E5=8F=A0=E6=A0=87=E9=A2=98?= =?UTF-8?q?=E8=B7=A8=E5=B1=82=E7=BA=A7=E5=B1=95=E5=BC=80=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20https://github.com/siyuan-note/siyuan/issues/5232?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/block.go | 2 +- kernel/model/file.go | 16 ++++++++-------- kernel/model/heading.go | 7 ++++--- kernel/model/repository.go | 16 ++++++++++++++++ kernel/model/transaction.go | 8 ++++---- kernel/treenode/heading.go | 25 ++++++++++++------------- 6 files changed, 45 insertions(+), 29 deletions(-) diff --git a/kernel/model/block.go b/kernel/model/block.go index 2bdf0702e..825e476b6 100644 --- a/kernel/model/block.go +++ b/kernel/model/block.go @@ -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) } diff --git a/kernel/model/file.go b/kernel/model/file.go index 9e21e3245..e9cde1e61 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -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) diff --git a/kernel/model/heading.go b/kernel/model/heading.go index 0f1dc83e1..7eaecfdc4 100644 --- a/kernel/model/heading.go +++ b/kernel/model/heading.go @@ -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") diff --git a/kernel/model/repository.go b/kernel/model/repository.go index 46f14db31..83ba62bc7 100644 --- a/kernel/model/repository.go +++ b/kernel/model/repository.go @@ -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)) diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index 9e31de010..0e6433d1d 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -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] } diff --git a/kernel/treenode/heading.go b/kernel/treenode/heading.go index 310f9f178..50d49918a 100644 --- a/kernel/treenode/heading.go +++ b/kernel/treenode/heading.go @@ -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) {