An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: 改进块引计数浮窗显示逻辑 https://github.com/siyuan-note/siyuan/issues/6853
Liang Ding2eb3e8ffc79b
diff --git a/kernel/api/filetree.go b/kernel/api/filetree.goindex 4c6dba7e5f..70de4e69ea 100644--- a/kernel/api/filetree.go+++ b/kernel/api/filetree.go@@ -705,8 +705,13 @@ func getDoc(c *gin.Context) {endID = endIDArg.(string)size = 36}+ isBacklinkArg := arg["isBacklink"]+ isBacklink := false+ if nil != isBacklinkArg {+ isBacklink = isBacklinkArg.(bool)+ }- blockCount, childBlockCount, content, parentID, parent2ID, rootID, typ, eof, boxID, docPath, err := model.GetDoc(startID, endID, id, index, keyword, mode, size)+ blockCount, childBlockCount, content, parentID, parent2ID, rootID, typ, eof, boxID, docPath, isBacklinkExpand, err := model.GetDoc(startID, endID, id, index, keyword, mode, size, isBacklink)if errors.Is(err, filelock.ErrUnableAccessFile) {ret.Code = 2ret.Data = id@@ -727,19 +732,20 @@ func getDoc(c *gin.Context) {isSyncing := model.IsSyncingFile(rootID)ret.Data = map[string]interface{}{- "id": id,- "mode": mode,- "parentID": parentID,- "parent2ID": parent2ID,- "rootID": rootID,- "type": typ,- "content": content,- "blockCount": blockCount,- "childBlockCount": childBlockCount,- "eof": eof,- "box": boxID,- "path": docPath,- "isSyncing": isSyncing,+ "id": id,+ "mode": mode,+ "parentID": parentID,+ "parent2ID": parent2ID,+ "rootID": rootID,+ "type": typ,+ "content": content,+ "blockCount": blockCount,+ "childBlockCount": childBlockCount,+ "eof": eof,+ "box": boxID,+ "path": docPath,+ "isSyncing": isSyncing,+ "isBacklinkExpand": isBacklinkExpand,}}diff --git a/kernel/model/backlink.go b/kernel/model/backlink.goindex 9cf0a2e95d..c0138fd3a2 100644--- a/kernel/model/backlink.go+++ b/kernel/model/backlink.go@@ -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)diff --git a/kernel/model/file.go b/kernel/model/file.goindex 7185895937..19d693d125 100644--- a/kernel/model/file.go+++ b/kernel/model/file.go@@ -452,7 +452,7 @@ func getMarkSpanEnd() string {return "</span>"}-func GetDoc(startID, endID, id string, index int, keyword string, mode int, size int) (blockCount, childBlockCount int, dom, parentID, parent2ID, rootID, typ string, eof bool, boxID, docPath string, err error) {+func GetDoc(startID, endID, id string, index int, keyword string, mode int, size int, isBacklink bool) (blockCount, childBlockCount int, dom, parentID, parent2ID, rootID, typ string, eof bool, boxID, docPath string, isBacklinkExpand bool, err error) {WaitForWritingFiles() // 写入数据时阻塞,避免获取到的数据不一致inputIndex := index@@ -477,9 +477,16 @@ func GetDoc(startID, endID, id string, index int, keyword string, mode int, sizereturn}+ if isBacklink { // 引用计数浮窗请求,需要按照反链逻辑组装 https://github.com/siyuan-note/siyuan/issues/6853+ if ast.NodeParagraph == node.Type {+ node = node.Parent+ }+ }+located := falseisDoc := ast.NodeDocument == node.TypeisHeading := ast.NodeHeading == node.Type+boxID = node.BoxdocPath = node.Pathif isDoc {@@ -582,16 +589,20 @@ func GetDoc(startID, endID, id string, index int, keyword string, mode int, size}var nodes []*ast.Node-- // 如果同时存在 startID 和 endID,则只加载 startID 和 endID 之间的块 [startID, endID]- if "" != startID && "" != endID {- nodes, eof = loadNodesByStartEnd(tree, startID, endID)- if 1 > len(nodes) {- // 按 mode 加载兜底+ if isBacklink {+ // 引用计数浮窗请求,需要按照反链逻辑组装 https://github.com/siyuan-note/siyuan/issues/6853+ nodes, isBacklinkExpand = getBacklinkRenderNodes(node)+ } else {+ // 如果同时存在 startID 和 endID,则只加载 startID 和 endID 之间的块 [startID, endID]+ if "" != startID && "" != endID {+ nodes, eof = loadNodesByStartEnd(tree, startID, endID)+ if 1 > len(nodes) {+ // 按 mode 加载兜底+ nodes, eof = loadNodesByMode(node, inputIndex, mode, size, isDoc, isHeading)+ }+ } else {nodes, eof = loadNodesByMode(node, inputIndex, mode, size, isDoc, isHeading)}- } else {- nodes, eof = loadNodesByMode(node, inputIndex, mode, size, isDoc, isHeading)}refCount := sql.QueryRootChildrenRefCount(rootID)