Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve the behavior of `Jump to the next/previous block of the parent block` in lists https://github.com/siyuan-note/siyuan/issues/15939

Daniel467ff96d0e86
diff --git a/kernel/model/block.go b/kernel/model/block.go
index 45190431bd..c22cafa176 100644
--- a/kernel/model/block.go
+++ b/kernel/model/block.go
@@ -196,78 +196,22 @@ func GetBlockSiblingID(id string) (parent, previous, next string) {
return
}
- node := treenode.GetNodeInTree(tree, id)
- if nil == node {
- return
- }
-
- if !node.IsBlock() {
- return
- }
-
- parentListCount := 0
- var parentListItem, current *ast.Node
- for p := node.Parent; nil != p; p = p.Parent {
- if ast.NodeListItem == p.Type {
- parentListCount++
- if 1 < parentListCount {
- parentListItem = p
- break
- }
- current = p.Parent
- }
- }
-
- if nil != parentListItem {
- parent = parentListItem.ID
-
- if parentListItem.Previous != nil {
- previous = parentListItem.Previous.ID
- if flb := treenode.FirstChildBlock(parentListItem.Previous); nil != flb {
- previous = flb.ID
- }
- }
-
- if parentListItem.Next != nil {
- next = parentListItem.Next.ID
- if flb := treenode.FirstChildBlock(parentListItem.Next); nil != flb {
- next = flb.ID
- }
- }
-
- if "" == previous && "" == next && nil != current {
- parent = current.ID
- if nil != current.Previous {
- previous = current.Previous.ID
- if flb := treenode.FirstChildBlock(current.Previous); nil != flb {
- previous = flb.ID
- }
- }
- if nil != current.Next {
- next = current.Next.ID
- if flb := treenode.FirstChildBlock(current.Next); nil != flb {
- next = flb.ID
- }
- }
- }
+ current := treenode.GetNodeInTree(tree, id)
+ if nil == current || !current.IsBlock() {
return
}
-
- if nil == current {
- current = node
- }
-
- if nil == current.Parent || !current.Parent.IsBlock() {
+ parentBlock := treenode.ParentBlock(current)
+ if nil == parentBlock {
return
}
- parent = current.Parent.ID
- if flb := treenode.FirstChildBlock(current.Parent); nil != flb {
+ parent = parentBlock.ID
+ if flb := treenode.FirstChildBlock(parentBlock); nil != flb {
parent = flb.ID
}
- if ast.NodeDocument == current.Parent.Type {
- parent = current.Parent.ID
+ if ast.NodeDocument == parentBlock.Type {
+ parent = parentBlock.ID
if nil != current.Previous && current.Previous.IsBlock() {
previous = current.Previous.ID
@@ -285,7 +229,6 @@ func GetBlockSiblingID(id string) (parent, previous, next string) {
return
}
- parentBlock := treenode.ParentBlock(current)
for ; nil != parentBlock; parentBlock = treenode.ParentBlock(parentBlock) {
if nil != parentBlock.Previous && parentBlock.Previous.IsBlock() {
previous = parentBlock.Previous.ID