mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Improve the behavior of Jump to parent block in lists https://github.com/siyuan-note/siyuan/issues/16516
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
43d2654213
commit
3e9bd1547c
1 changed files with 62 additions and 48 deletions
|
|
@ -206,66 +206,80 @@ func GetBlockSiblingID(id string) (parent, previous, next string) {
|
|||
return
|
||||
}
|
||||
|
||||
if nil != current.Parent && ast.NodeListItem == current.Parent.Type {
|
||||
current = current.Parent
|
||||
}
|
||||
|
||||
parentBlock := treenode.ParentBlock(current)
|
||||
if nil == parentBlock {
|
||||
return
|
||||
}
|
||||
|
||||
parent = parentBlock.ID
|
||||
if ast.NodeDocument == parentBlock.Type {
|
||||
parent = treenode.FirstLeafBlock(parentBlock).ID
|
||||
|
||||
if nil != current.Previous && current.Previous.IsBlock() {
|
||||
previous = current.Previous.ID
|
||||
if flb := treenode.FirstChildBlock(current.Previous); nil != flb {
|
||||
previous = flb.ID
|
||||
if !current.ParentIs(ast.NodeList) { // 当前块不在列表内的情况
|
||||
parentBlock := treenode.ParentBlock(current)
|
||||
if nil != parentBlock {
|
||||
parent = parentBlock.ID
|
||||
if nil != parentBlock.Previous {
|
||||
previous = parentBlock.Previous.ID
|
||||
}
|
||||
}
|
||||
|
||||
if nil != current.Next && current.Next.IsBlock() {
|
||||
next = current.Next.ID
|
||||
if flb := treenode.FirstChildBlock(current.Next); nil != flb {
|
||||
next = flb.ID
|
||||
if nil != parentBlock.Next {
|
||||
next = parentBlock.Next.ID
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
parentCount := 0
|
||||
for ; nil != parentBlock; parentBlock = treenode.ParentBlock(parentBlock) {
|
||||
if ast.NodeDocument == parentBlock.Type {
|
||||
break
|
||||
}
|
||||
|
||||
if ast.NodeList == parentBlock.Type || ast.NodeBlockquote == parentBlock.Type || ast.NodeSuperBlock == parentBlock.Type || ast.NodeCallout == parentBlock.Type {
|
||||
parentCount++
|
||||
continue
|
||||
}
|
||||
|
||||
if ast.NodeListItem == parentBlock.Type {
|
||||
if 1 > parentCount {
|
||||
parentBlock = treenode.ParentBlock(parentBlock)
|
||||
if ast.NodeListItem != current.Type && ast.NodeList != current.Parent.Type { // 当前块是列表内的块,但不是列表项或列表的情况
|
||||
var listParent, listParent2 *ast.Node
|
||||
listParentCount := 0
|
||||
for parentBlock := treenode.ParentBlock(current); nil != parentBlock; parentBlock = treenode.ParentBlock(parentBlock) {
|
||||
if ast.NodeListItem == parentBlock.Type {
|
||||
listParentCount++
|
||||
if 1 < listParentCount {
|
||||
listParent2 = parentBlock
|
||||
break
|
||||
}
|
||||
listParent = parentBlock
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if 1 == listParentCount { // 列表只有一层的情况
|
||||
if nil != listParent {
|
||||
parent = listParent.ID
|
||||
previous, next = getPreNext(listParent)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
parent = listParent2.ID
|
||||
previous, next = getPreNext(listParent)
|
||||
return
|
||||
}
|
||||
|
||||
if ast.NodeListItem == current.Type {
|
||||
// 当前块是列表项的情况
|
||||
parentBlock := treenode.ParentBlock(current)
|
||||
if nil != parentBlock {
|
||||
parentBlock = treenode.ParentBlock(parentBlock)
|
||||
}
|
||||
break
|
||||
}
|
||||
if ast.NodeDocument == parentBlock.Type {
|
||||
parentBlock = treenode.FirstLeafBlock(parentBlock)
|
||||
parent = parentBlock.ID
|
||||
} else {
|
||||
parent = parentBlock.ID
|
||||
if nil != parentBlock {
|
||||
parent = parentBlock.ID
|
||||
previous, next = getPreNext(current)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if nil != parentBlock.Previous {
|
||||
previous = parentBlock.Previous.ID
|
||||
// 当前块是列表的情况
|
||||
parentBlock := treenode.ParentBlock(current)
|
||||
if nil != parentBlock {
|
||||
parent = parentBlock.ID
|
||||
previous, next = getPreNext(current)
|
||||
return
|
||||
}
|
||||
if nil != parentBlock.Next {
|
||||
next = parentBlock.Next.ID
|
||||
return
|
||||
}
|
||||
|
||||
func getPreNext(parent *ast.Node) (previous, next string) {
|
||||
if nil != parent {
|
||||
if nil != parent.Previous {
|
||||
previous = parent.Previous.ID
|
||||
}
|
||||
if nil != parent.Next {
|
||||
next = parent.Next.ID
|
||||
}
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue