diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2024-08-13 11:19:54 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2024-08-29 17:08:23 +0900 |
| commit | 6a67712944bbba3bfbb04e6ad02f7ae7d55cd238 (patch) | |
| tree | 90e9c6c6d4655f26b76f29c73bcc67786ea1f0f1 /src/pattern.go | |
| parent | e8a690928db0acf8c3eb6887fe92c58fdc3ab167 (diff) | |
| download | fzf-6a67712944bbba3bfbb04e6ad02f7ae7d55cd238.tar.gz | |
Implement exact-boundary match type
Close #3963
Diffstat (limited to 'src/pattern.go')
| -rw-r--r-- | src/pattern.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/pattern.go b/src/pattern.go index ee1b88a5..c736be3c 100644 --- a/src/pattern.go +++ b/src/pattern.go @@ -23,6 +23,7 @@ type termType int const ( termFuzzy termType = iota termExact + termExactBoundary termPrefix termSuffix termEqual @@ -147,6 +148,7 @@ func BuildPattern(cache *ChunkCache, patternCache map[string]*Pattern, fuzzy boo ptr.procFun[termFuzzy] = fuzzyAlgo ptr.procFun[termEqual] = algo.EqualMatch ptr.procFun[termExact] = algo.ExactMatchNaive + ptr.procFun[termExactBoundary] = algo.ExactMatchBoundary ptr.procFun[termPrefix] = algo.PrefixMatch ptr.procFun[termSuffix] = algo.SuffixMatch @@ -193,7 +195,14 @@ func parseTerms(fuzzy bool, caseMode Case, normalize bool, str string) []termSet text = text[:len(text)-1] } - if strings.HasPrefix(text, "'") { + if fuzzy && len(text) > 2 && strings.HasPrefix(text, "'") && strings.HasSuffix(text, "'") || + !fuzzy && !strings.HasPrefix(text, "'") && strings.HasSuffix(text, "'") { + typ = termExactBoundary + if fuzzy { + text = text[1:] + } + text = text[:len(text)-1] + } else if strings.HasPrefix(text, "'") { // Flip exactness if fuzzy && !inv { typ = termExact |
