From d2f8bccc370b4089ad837fc942c02775817ed8f6 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Thu, 25 Sep 2025 17:35:01 +0800 Subject: [PATCH] :art: Improve `Jump to the next/previous block of the parent block` for container blocks https://github.com/siyuan-note/siyuan/issues/15940 Signed-off-by: Daniel <845765@qq.com> --- kernel/model/block.go | 70 ++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/kernel/model/block.go b/kernel/model/block.go index a97786960..45190431b 100644 --- a/kernel/model/block.go +++ b/kernel/model/block.go @@ -257,42 +257,52 @@ func GetBlockSiblingID(id string) (parent, previous, next string) { current = node } - if nil != current.Parent && current.Parent.IsBlock() { + if nil == current.Parent || !current.Parent.IsBlock() { + return + } + + parent = current.Parent.ID + if flb := treenode.FirstChildBlock(current.Parent); nil != flb { + parent = flb.ID + } + + if ast.NodeDocument == current.Parent.Type { parent = current.Parent.ID - if flb := treenode.FirstChildBlock(current.Parent); nil != flb { - parent = flb.ID + + if nil != current.Previous && current.Previous.IsBlock() { + previous = current.Previous.ID + if flb := treenode.FirstChildBlock(current.Previous); nil != flb { + previous = flb.ID + } } - if ast.NodeDocument == current.Parent.Type { - parent = current.Parent.ID + if nil != current.Next && current.Next.IsBlock() { + next = current.Next.ID + if flb := treenode.FirstChildBlock(current.Next); nil != flb { + next = flb.ID + } + } + return + } - if nil != current.Previous && current.Previous.IsBlock() { - previous = current.Previous.ID - if flb := treenode.FirstChildBlock(current.Previous); nil != flb { - previous = flb.ID - } + parentBlock := treenode.ParentBlock(current) + for ; nil != parentBlock; parentBlock = treenode.ParentBlock(parentBlock) { + if nil != parentBlock.Previous && parentBlock.Previous.IsBlock() { + previous = parentBlock.Previous.ID + if flb := treenode.FirstChildBlock(parentBlock.Previous); nil != flb { + previous = flb.ID } - - if nil != current.Next && current.Next.IsBlock() { - next = current.Next.ID - if flb := treenode.FirstChildBlock(current.Next); nil != flb { - next = flb.ID - } - } - } else { - if nil != current.Parent.Previous && current.Parent.Previous.IsBlock() { - previous = current.Parent.Previous.ID - if flb := treenode.FirstChildBlock(current.Parent.Previous); nil != flb { - previous = flb.ID - } - } - - if nil != current.Parent.Next && current.Parent.Next.IsBlock() { - next = current.Parent.Next.ID - if flb := treenode.FirstChildBlock(current.Parent.Next); nil != flb { - next = flb.ID - } + break + } + } + parentBlock = treenode.ParentBlock(current) + for ; nil != parentBlock; parentBlock = treenode.ParentBlock(parentBlock) { + if nil != parentBlock.Next && parentBlock.Next.IsBlock() { + next = parentBlock.Next.ID + if flb := treenode.FirstChildBlock(parentBlock.Next); nil != flb { + next = flb.ID } + break } } return