From bc1ab2b52f6154b9c9efb45730b7a27a6388725a Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 24 Feb 2023 10:04:25 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E8=99=9A=E6=8B=9F=E5=BC=95=E7=94=A8?= =?UTF-8?q?=E5=92=8C=E5=8F=8D=E9=93=BE=E6=8F=90=E5=8F=8A=E5=85=B3=E9=94=AE?= =?UTF-8?q?=E5=AD=97=E6=8C=89=E6=9C=80=E9=95=BF=E5=8C=B9=E9=85=8D=E4=BC=98?= =?UTF-8?q?=E5=85=88=20Fix=20https://github.com/siyuan-note/siyuan/issues/?= =?UTF-8?q?7465?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/search.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/model/search.go b/kernel/model/search.go index 8288f0da3..25b4fbf15 100644 --- a/kernel/model/search.go +++ b/kernel/model/search.go @@ -986,6 +986,9 @@ func markReplaceSpan(n *ast.Node, unlinks *[]*ast.Node, keywords []string, markS // markReplaceSpanWithSplit 用于处理虚拟引用和反链提及高亮。 func markReplaceSpanWithSplit(text string, keywords []string, replacementStart, replacementEnd string) (ret string) { + // 虚拟引用和反链提及关键字按最长匹配优先 https://github.com/siyuan-note/siyuan/issues/7465 + sort.Slice(keywords, func(i, j int) bool { return len(keywords[i]) > len(keywords[j]) }) + tmp := search.EncloseHighlighting(text, keywords, replacementStart, replacementEnd, Conf.Search.CaseSensitive) parts := strings.Split(tmp, replacementEnd) buf := bytes.Buffer{}