From efbcd5a6833939c3e9c1347587fd5118e8f3705e Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 16 Aug 2024 18:02:36 +0900 Subject: [PATCH] Require quotes on both sides for boundary matching even in --exact mode Only requiring '-suffix in --exact mode is confusing and not straightforward. Requiring '-prefix in --exact mode means that the users can experience unintended mode switches while typing. e.g. 'it -> fuzzy (many results) 'it' -> boundary (few results) 'it's -> fuzzy (many results) However, user who intends to input a boundary query should not be interested in the intermediate results, and the number of matches decreases as she types, so it should be okay. On the other hand, user who does intend to type "it's" will be surprised by the sudden decrease of the match count, but eventually get the right result. --- src/pattern.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/pattern.go b/src/pattern.go index c736be3..11bed5f 100644 --- a/src/pattern.go +++ b/src/pattern.go @@ -195,13 +195,9 @@ func parseTerms(fuzzy bool, caseMode Case, normalize bool, str string) []termSet text = text[:len(text)-1] } - if fuzzy && len(text) > 2 && strings.HasPrefix(text, "'") && strings.HasSuffix(text, "'") || - !fuzzy && !strings.HasPrefix(text, "'") && strings.HasSuffix(text, "'") { + if len(text) > 2 && strings.HasPrefix(text, "'") && strings.HasSuffix(text, "'") { typ = termExactBoundary - if fuzzy { - text = text[1:] - } - text = text[:len(text)-1] + text = text[1 : len(text)-1] } else if strings.HasPrefix(text, "'") { // Flip exactness if fuzzy && !inv {