mirror of
https://github.com/junegunn/fzf.git
synced 2025-05-19 04:40:22 -07:00
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
This commit is contained in:
parent
84e2262ad6
commit
9abf2c8c9c
@ -432,8 +432,13 @@ func (p *Pattern) transformInput(item *Item) []Token {
|
|||||||
|
|
||||||
tokens := Tokenize(item.text.ToString(), p.delimiter)
|
tokens := Tokenize(item.text.ToString(), p.delimiter)
|
||||||
ret := Transform(tokens, p.nth)
|
ret := Transform(tokens, p.nth)
|
||||||
// TODO: We could apply StripLastDelimiter to exclude the last delimiter from
|
// Strip the last delimiter to allow suffix match
|
||||||
// the search allowing suffix match with a string or a regex delimiter.
|
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}
|
item.transformed = &transformed{p.revision, ret}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,11 @@ type Delimiter struct {
|
|||||||
str *string
|
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.
|
// String returns the string representation of a Delimiter.
|
||||||
func (d Delimiter) String() string {
|
func (d Delimiter) String() string {
|
||||||
return fmt.Sprintf("Delimiter{regex: %v, str: &%q}", d.regex, *d.str)
|
return fmt.Sprintf("Delimiter{regex: %v, str: &%q}", d.regex, *d.str)
|
||||||
|
@ -52,6 +52,12 @@ class TestFilter < TestBase
|
|||||||
`find . -print0 | #{FZF} --read0 -e -f "^#{lines.last}$"`.chomp
|
`find . -print0 | #{FZF} --read0 -e -f "^#{lines.last}$"`.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_nth_suffix_match
|
||||||
|
assert_equal \
|
||||||
|
'foo,bar,baz',
|
||||||
|
`echo foo,bar,baz | #{FZF} -d, -f'bar$' -n2`.chomp
|
||||||
|
end
|
||||||
|
|
||||||
def test_with_nth_basic
|
def test_with_nth_basic
|
||||||
writelines(['hello world ', 'byebye'])
|
writelines(['hello world ', 'byebye'])
|
||||||
assert_equal \
|
assert_equal \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user