mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
🐛 正则表达式搜索失效 Fix https://github.com/siyuan-note/siyuan/issues/7529
This commit is contained in:
parent
5c21de0a0c
commit
b93af1965e
1 changed files with 5 additions and 9 deletions
|
|
@ -209,6 +209,9 @@ func FindReplace(keyword, replacement string, ids []string, method int) (err err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r, _ := regexp.Compile(keyword)
|
||||||
|
escapedKey := util.EscapeHTML(keyword)
|
||||||
|
escapedR, _ := regexp.Compile(escapedKey)
|
||||||
ids = gulu.Str.RemoveDuplicatedElem(ids)
|
ids = gulu.Str.RemoveDuplicatedElem(ids)
|
||||||
var renameRoots []*ast.Node
|
var renameRoots []*ast.Node
|
||||||
renameRootTitles := map[string]string{}
|
renameRootTitles := map[string]string{}
|
||||||
|
|
@ -238,7 +241,6 @@ func FindReplace(keyword, replacement string, ids []string, method int) (err err
|
||||||
renameRoots = append(renameRoots, n)
|
renameRoots = append(renameRoots, n)
|
||||||
}
|
}
|
||||||
} else if 3 == method {
|
} else if 3 == method {
|
||||||
r, _ := regexp.Compile(keyword)
|
|
||||||
if nil != r && r.MatchString(title) {
|
if nil != r && r.MatchString(title) {
|
||||||
renameRootTitles[n.ID] = r.ReplaceAllString(title, replacement)
|
renameRootTitles[n.ID] = r.ReplaceAllString(title, replacement)
|
||||||
renameRoots = append(renameRoots, n)
|
renameRoots = append(renameRoots, n)
|
||||||
|
|
@ -250,22 +252,19 @@ func FindReplace(keyword, replacement string, ids []string, method int) (err err
|
||||||
n.Tokens = bytes.ReplaceAll(n.Tokens, []byte(keyword), []byte(replacement))
|
n.Tokens = bytes.ReplaceAll(n.Tokens, []byte(keyword), []byte(replacement))
|
||||||
}
|
}
|
||||||
} else if 3 == method {
|
} else if 3 == method {
|
||||||
r, _ := regexp.Compile(keyword)
|
|
||||||
if nil != r && r.MatchString(string(n.Tokens)) {
|
if nil != r && r.MatchString(string(n.Tokens)) {
|
||||||
n.Tokens = []byte(r.ReplaceAllString(string(n.Tokens), replacement))
|
n.Tokens = []byte(r.ReplaceAllString(string(n.Tokens), replacement))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ast.NodeTextMark:
|
case ast.NodeTextMark:
|
||||||
if n.IsTextMarkType("code") {
|
if n.IsTextMarkType("code") {
|
||||||
escapedKey := util.EscapeHTML(keyword)
|
|
||||||
if 0 == method {
|
if 0 == method {
|
||||||
if strings.Contains(n.TextMarkTextContent, escapedKey) {
|
if strings.Contains(n.TextMarkTextContent, escapedKey) {
|
||||||
n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, escapedKey, replacement)
|
n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, escapedKey, replacement)
|
||||||
}
|
}
|
||||||
} else if 3 == method {
|
} else if 3 == method {
|
||||||
r, _ := regexp.Compile(escapedKey)
|
if nil != escapedR && escapedR.MatchString(n.TextMarkTextContent) {
|
||||||
if nil != r && r.MatchString(n.TextMarkTextContent) {
|
n.TextMarkTextContent = escapedR.ReplaceAllString(n.TextMarkTextContent, replacement)
|
||||||
n.TextMarkTextContent = r.ReplaceAllString(n.TextMarkTextContent, replacement)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -274,7 +273,6 @@ func FindReplace(keyword, replacement string, ids []string, method int) (err err
|
||||||
n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, keyword, replacement)
|
n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, keyword, replacement)
|
||||||
}
|
}
|
||||||
} else if 3 == method {
|
} else if 3 == method {
|
||||||
r, _ := regexp.Compile(keyword)
|
|
||||||
if nil != r && r.MatchString(n.TextMarkTextContent) {
|
if nil != r && r.MatchString(n.TextMarkTextContent) {
|
||||||
n.TextMarkTextContent = r.ReplaceAllString(n.TextMarkTextContent, replacement)
|
n.TextMarkTextContent = r.ReplaceAllString(n.TextMarkTextContent, replacement)
|
||||||
}
|
}
|
||||||
|
|
@ -298,7 +296,6 @@ func FindReplace(keyword, replacement string, ids []string, method int) (err err
|
||||||
n.TextMarkAHref = strings.ReplaceAll(n.TextMarkAHref, keyword, replacement)
|
n.TextMarkAHref = strings.ReplaceAll(n.TextMarkAHref, keyword, replacement)
|
||||||
}
|
}
|
||||||
} else if 3 == method {
|
} else if 3 == method {
|
||||||
r, _ := regexp.Compile(keyword)
|
|
||||||
if nil != r {
|
if nil != r {
|
||||||
if r.MatchString(n.TextMarkTextContent) {
|
if r.MatchString(n.TextMarkTextContent) {
|
||||||
n.TextMarkTextContent = r.ReplaceAllString(n.TextMarkTextContent, replacement)
|
n.TextMarkTextContent = r.ReplaceAllString(n.TextMarkTextContent, replacement)
|
||||||
|
|
@ -637,7 +634,6 @@ func fullTextSearchByKeyword(query, boxFilter, pathFilter, typeFilter string, or
|
||||||
|
|
||||||
func fullTextSearchByRegexp(exp, boxFilter, pathFilter, typeFilter, orderBy string, beforeLen int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
|
func fullTextSearchByRegexp(exp, boxFilter, pathFilter, typeFilter, orderBy string, beforeLen int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
|
||||||
exp = gulu.Str.RemoveInvisible(exp)
|
exp = gulu.Str.RemoveInvisible(exp)
|
||||||
exp = regexp.QuoteMeta(exp)
|
|
||||||
|
|
||||||
fieldFilter := fieldRegexp(exp)
|
fieldFilter := fieldRegexp(exp)
|
||||||
stmt := "SELECT * FROM `blocks` WHERE " + fieldFilter + " AND type IN " + typeFilter
|
stmt := "SELECT * FROM `blocks` WHERE " + fieldFilter + " AND type IN " + typeFilter
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue