diff --git a/kernel/model/backlink.go b/kernel/model/backlink.go index 07f44314a..8174b32a2 100644 --- a/kernel/model/backlink.go +++ b/kernel/model/backlink.go @@ -151,9 +151,35 @@ func GetBacklinkDoc(defID, refTreeID, keyword string, containChildren bool) (ret } sortBacklinks(ret, refTree) + + for i := len(ret) - 1; 0 < i; i-- { + curPaths := ret[i].BlockPaths + prevPaths := ret[i-1].BlockPaths + // 如果当前反链的面包屑和前一个反链的面包屑一致,则清空当前反链的面包屑以简化显示 + if blockPathsEqual(curPaths, prevPaths) { + ret[i].BlockPaths = []*BlockPath{} + } + } return } +func blockPathsEqual(paths1, paths2 []*BlockPath) bool { + if len(paths1) != len(paths2) { + return false + } + if 2 < len(paths1) { + paths1 = paths1[:len(paths1)-1] + paths2 = paths2[:len(paths2)-1] + } + + for i := range paths1 { + if paths1[i].ID != paths2[i].ID { + return false + } + } + return true +} + func sortBacklinks(backlinks []*Backlink, tree *parse.Tree) { contentSorts := map[string]int{} sortVal := 0 @@ -206,13 +232,16 @@ func buildBacklink(refID string, refTree *parse.Tree, keywords []string, luteEng } dom := renderBlockDOMByNodes(renderNodes, luteEngine) - blockPaths := []*BlockPath{} - if (nil != n.Parent && ast.NodeDocument != n.Parent.Type && nil != n.Parent.Parent && ast.NodeDocument != n.Parent.Parent.Type) || nil != treenode.HeadingParent(n) { + var blockPaths []*BlockPath + if (nil != n.Parent && ast.NodeDocument != n.Parent.Type) || 0 != treenode.HeadingLevel(n) { // 仅在多于一层时才显示面包屑,这样界面展示更加简洁 // The backlink panel no longer displays breadcrumbs of the first-level blocks https://github.com/siyuan-note/siyuan/issues/12862 // Improve the backlink panel breadcrumb and block sorting https://github.com/siyuan-note/siyuan/issues/13008 blockPaths = buildBlockBreadcrumb(n, nil, false) } + if 1 > len(blockPaths) { + blockPaths = []*BlockPath{} + } ret = &Backlink{DOM: dom, BlockPaths: blockPaths, Expand: expand, node: n} return } diff --git a/kernel/model/blockinfo.go b/kernel/model/blockinfo.go index a3821e2b9..635b5c2cb 100644 --- a/kernel/model/blockinfo.go +++ b/kernel/model/blockinfo.go @@ -420,7 +420,7 @@ func BuildBlockBreadcrumb(id string, excludeTypes []string) (ret []*BlockPath, e return } -func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string, displayCurrentNodeContent bool) (ret []*BlockPath) { +func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string, displayCurrentNode bool) (ret []*BlockPath) { ret = []*BlockPath{} if nil == node { return @@ -481,9 +481,8 @@ func buildBlockBreadcrumb(node *ast.Node, excludeTypes []string, displayCurrentN name = strings.ReplaceAll(name, editor.Caret, "") name = util.EscapeHTML(name) - if parent == node && !displayCurrentNodeContent { - // 反链中不显示当前块内容 https://github.com/siyuan-note/siyuan/issues/12862#issuecomment-2426406327 - name = "" + if parent == node && !displayCurrentNode { + add = false } if add {