diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2025-02-12 20:50:01 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2025-02-12 20:53:32 +0900 |
| commit | 9abf2c8c9ca625f30ff0775316f51ad798a922f3 (patch) | |
| tree | 0ed698337059cc4c5e096df4bc0827e4d9dea56e /src | |
| parent | 84e2262ad63df2112f16b2a80fc661294c3da45e (diff) | |
| download | fzf-9abf2c8c9ca625f30ff0775316f51ad798a922f3.tar.gz | |
Allow suffix match on --nth with custom --delimiter
When --nth is used with a custom --delimiter, the last delimiter was
included in the search scope, forcing you to write the delimiter in
a suffix-match query. This commit removes the last delimiter from the
search scope.
# No need to write 'bar,$'
echo foo,bar,baz | fzf --delimiter , --nth 2 --filter 'bar$'
This can be seen as a breaking change, but I'm gonna say it's a bug fix.
Fix #3983
Diffstat (limited to 'src')
| -rw-r--r-- | src/pattern.go | 9 | ||||
| -rw-r--r-- | src/tokenizer.go | 5 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/pattern.go b/src/pattern.go index 93640cb6..8e6966c3 100644 --- a/src/pattern.go +++ b/src/pattern.go @@ -432,8 +432,13 @@ func (p *Pattern) transformInput(item *Item) []Token { tokens := Tokenize(item.text.ToString(), p.delimiter) ret := Transform(tokens, p.nth) - // TODO: We could apply StripLastDelimiter to exclude the last delimiter from - // the search allowing suffix match with a string or a regex delimiter. + // Strip the last delimiter to allow suffix match + if len(ret) > 0 && !p.delimiter.IsAwk() { + chars := ret[len(ret)-1].text + stripped := StripLastDelimiter(chars.ToString(), p.delimiter) + newChars := util.ToChars(stringBytes(stripped)) + ret[len(ret)-1].text = &newChars + } item.transformed = &transformed{p.revision, ret} return ret } diff --git a/src/tokenizer.go b/src/tokenizer.go index aaddd17d..573a3576 100644 --- a/src/tokenizer.go +++ b/src/tokenizer.go @@ -78,6 +78,11 @@ type Delimiter struct { str *string } +// IsAwk returns true if the delimiter is an AWK-style delimiter +func (d Delimiter) IsAwk() bool { + return d.regex == nil && d.str == nil +} + // String returns the string representation of a Delimiter. func (d Delimiter) String() string { return fmt.Sprintf("Delimiter{regex: %v, str: &%q}", d.regex, *d.str) |
