From 4fb16364a791d32d4591b40abe8d2fa3cb5ad65a Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 14 Aug 2022 11:46:50 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E4=BD=BF=E7=94=A8=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E8=AF=AD=E6=B3=95=E6=90=9C=E7=B4=A2=E6=97=B6=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=8C=BA=E9=AB=98=E4=BA=AE=E4=B8=8D=E6=AD=A3=E7=A1=AE=20Fix=20?= =?UTF-8?q?https://github.com/siyuan-note/siyuan/issues/5632?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/file.go | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/kernel/model/file.go b/kernel/model/file.go index b782d475d..9f82c55d8 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -635,22 +635,31 @@ func GetDoc(startID, endID, id string, index int, keyword string, mode int, size if ast.NodeText == n.Type { if 0 < len(keywords) { - // 搜索高亮 - text := string(n.Tokens) - text = search.EncloseHighlighting(text, keywords, "", "", Conf.Search.CaseSensitive) - n.Tokens = gulu.Str.ToBytes(text) - if bytes.Contains(n.Tokens, []byte("search-mark")) { - n.Tokens = bytes.ReplaceAll(n.Tokens, []byte("\\"), []byte("\\\\")) - linkTree := parse.Inline("", n.Tokens, luteEngine.ParseOptions) - var children []*ast.Node - for c := linkTree.Root.FirstChild.FirstChild; nil != c; c = c.Next { - children = append(children, c) + hitBlock := false + for p := n.Parent; nil != p; p = p.Parent { + if p.ID == id { + hitBlock = true + break } - for _, c := range children { - n.InsertBefore(c) + } + if hitBlock { + // 搜索高亮 + text := string(n.Tokens) + text = search.EncloseHighlighting(text, keywords, "", "", Conf.Search.CaseSensitive) + n.Tokens = gulu.Str.ToBytes(text) + if bytes.Contains(n.Tokens, []byte("search-mark")) { + n.Tokens = bytes.ReplaceAll(n.Tokens, []byte("\\"), []byte("\\\\")) + linkTree := parse.Inline("", n.Tokens, luteEngine.ParseOptions) + var children []*ast.Node + for c := linkTree.Root.FirstChild.FirstChild; nil != c; c = c.Next { + children = append(children, c) + } + for _, c := range children { + n.InsertBefore(c) + } + unlinks = append(unlinks, n) + return ast.WalkContinue } - unlinks = append(unlinks, n) - return ast.WalkContinue } }