🎨 改进块引计数浮窗显示逻辑 https://github.com/siyuan-note/siyuan/issues/6853

This commit is contained in:
Liang Ding 2022-12-24 12:05:55 +08:00
parent a20a338e6d
commit 2eb3e8ffc7
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 91 additions and 70 deletions

View file

@ -147,53 +147,7 @@ func buildBacklink(refID string, refTree *parse.Tree, mentionKeywords []string,
return
}
var renderNodes []*ast.Node
expand := true
if ast.NodeListItem == n.Type {
if nil == n.FirstChild {
return
}
c := n.FirstChild
if 3 == n.ListData.Typ {
c = n.FirstChild.Next
}
if c != n.LastChild { // 存在子列表
for liFirstBlockSpan := c.FirstChild; nil != liFirstBlockSpan; liFirstBlockSpan = liFirstBlockSpan.Next {
if treenode.IsBlockRef(liFirstBlockSpan) {
continue
}
if "" != strings.TrimSpace(liFirstBlockSpan.Text()) {
expand = false
break
}
}
}
renderNodes = append(renderNodes, n)
} else if ast.NodeHeading == n.Type {
c := n.FirstChild
if nil == c {
return
}
for headingFirstSpan := c; nil != headingFirstSpan; headingFirstSpan = headingFirstSpan.Next {
if treenode.IsBlockRef(headingFirstSpan) {
continue
}
if "" != strings.TrimSpace(headingFirstSpan.Text()) {
expand = false
break
}
}
renderNodes = append(renderNodes, n)
cc := treenode.HeadingChildren(n)
renderNodes = append(renderNodes, cc...)
} else {
renderNodes = append(renderNodes, n)
}
renderNodes, expand := getBacklinkRenderNodes(n)
if 0 < len(mentionKeywords) {
for _, renderNode := range renderNodes {
@ -241,6 +195,56 @@ func buildBacklink(refID string, refTree *parse.Tree, mentionKeywords []string,
return
}
func getBacklinkRenderNodes(n *ast.Node) (ret []*ast.Node, expand bool) {
expand = true
if ast.NodeListItem == n.Type {
if nil == n.FirstChild {
return
}
c := n.FirstChild
if 3 == n.ListData.Typ {
c = n.FirstChild.Next
}
if c != n.LastChild { // 存在子列表
for liFirstBlockSpan := c.FirstChild; nil != liFirstBlockSpan; liFirstBlockSpan = liFirstBlockSpan.Next {
if treenode.IsBlockRef(liFirstBlockSpan) {
continue
}
if "" != strings.TrimSpace(liFirstBlockSpan.Text()) {
expand = false
break
}
}
}
ret = append(ret, n)
} else if ast.NodeHeading == n.Type {
c := n.FirstChild
if nil == c {
return
}
for headingFirstSpan := c; nil != headingFirstSpan; headingFirstSpan = headingFirstSpan.Next {
if treenode.IsBlockRef(headingFirstSpan) {
continue
}
if "" != strings.TrimSpace(headingFirstSpan.Text()) {
expand = false
break
}
}
ret = append(ret, n)
cc := treenode.HeadingChildren(n)
ret = append(ret, cc...)
} else {
ret = append(ret, n)
}
return
}
func GetBacklink2(id, keyword, mentionKeyword string, sortMode, mentionSortMode int) (boxID string, backlinks, backmentions []*Path, linkRefsCount, mentionsCount int) {
keyword = strings.TrimSpace(keyword)
mentionKeyword = strings.TrimSpace(mentionKeyword)