🎨 Improve doc dynamic loading

This commit is contained in:
Daniel 2023-09-18 10:05:15 +08:00
parent 111608fd37
commit 57f9c4ddc1
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -681,6 +681,19 @@ func GetDoc(startID, endID, id string, index int, query string, queryTypes map[s
if 1 > len(nodes) {
// 按 mode 加载兜底
nodes, eof = loadNodesByMode(node, inputIndex, mode, size, isDoc, isHeading)
} else {
// 文档块没有指定 index 时需要计算 index否则初次打开文档时 node-index 会为 0导致首次 Ctrl+Home 无法回到顶部
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering {
return ast.WalkContinue
}
index++
if nodes[0].ID == n.ID {
return ast.WalkStop
}
return ast.WalkContinue
})
}
} else {
nodes, eof = loadNodesByMode(node, inputIndex, mode, size, isDoc, isHeading)