From 0a87b9aed89c3ad516dd3ad01aa795ce09617607 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 15 Dec 2024 11:54:09 +0800 Subject: [PATCH] :art: Search preview area supports memo positioning https://github.com/siyuan-note/siyuan/issues/13465 --- kernel/model/file.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kernel/model/file.go b/kernel/model/file.go index 06603f359..909010e41 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -648,6 +648,7 @@ func GetDoc(startID, endID, id string, index int, query string, queryTypes map[s } } + existKeywords := 0 < len(keywords) for _, n := range nodes { var unlinks []*ast.Node ast.Walk(n, func(n *ast.Node, entering bool) ast.WalkStatus { @@ -679,7 +680,7 @@ func GetDoc(startID, endID, id string, index int, query string, queryTypes map[s } } - if highlight && 0 < len(keywords) { + if highlight && existKeywords { hitBlock := false for p := n.Parent; nil != p; p = p.Parent { if p.ID == id { @@ -702,6 +703,16 @@ func GetDoc(startID, endID, id string, index int, query string, queryTypes map[s } } + if existKeywords && id == n.ID { + inlines := n.ChildrenByType(ast.NodeTextMark) + for _, inline := range inlines { + if inline.IsTextMarkType("inline-memo") && util.ContainsSubStr(inline.TextMarkInlineMemoContent, keywords) { + // 支持行级备注搜索定位 https://github.com/siyuan-note/siyuan/issues/13465 + keywords = append(keywords, inline.TextMarkTextContent) + } + } + } + if processVirtualRef(n, &unlinks, virtualBlockRefKeywords, refCount, luteEngine) { return ast.WalkContinue } @@ -726,6 +737,7 @@ func GetDoc(startID, endID, id string, index int, query string, queryTypes map[s keyword = strings.TrimSuffix(keyword, "#") keywords[i] = keyword } + keywords = gulu.Str.RemoveDuplicatedElem(keywords) go setRecentDocByTree(tree) return