Skip to content
Myr

With a non-default --delimiter, --{accept,with}-nth should not remove trailing whitespaces

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent d324580 · Browse files · 2 files+9 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+9 added−7 removed

  • tests:+4 added−4 removed
  • other:+5 added−3 removed

2 files+9 added−7 removed

modified:src/tokenizer.go+5 added-3 removed
216 unmodified lines
217 }218 return withPrefixLengths(tokens, 0)219}220221// StripLastDelimiter removes the trailing delimiter and whitespaces221// StripLastDelimiter removes the trailing delimiter222func StripLastDelimiter(str string, delimiter Delimiter) string {223 if delimiter.str != nil {224 str = strings.TrimSuffix(str, *delimiter.str)225 } else if delimiter.regex != nil {224 return strings.TrimSuffix(str, *delimiter.str)225 }226 if delimiter.regex != nil {227 locs := delimiter.regex.FindAllStringIndex(str, -1)228 if len(locs) > 0 {229 lastLoc := locs[len(locs)-1]230 if lastLoc[1] == len(str) {231 str = str[:lastLoc[0]]232 }233 }234 return str235 }236 return strings.TrimRightFunc(str, unicode.IsSpace)237}238
100 unmodified lines
modified:test/test_core.rb+4 added-4 removed
2093 unmodified lines
2094 def test_accept_nth_string_delimiter2095 tmux.send_keys %(echo "foo ,bar,baz" | #{FZF} -d, --accept-nth 2,2,1,3,1 --sync --bind start:accept > #{tempname}), :Enter2096 wait do2097 assert_path_exists tempname2098 # Last delimiter and the whitespaces are removed2099 assert_equal ['bar,bar,foo ,bazfoo'], File.readlines(tempname, chomp: true)2098 # Last delimiter is removed2099 assert_equal ['bar,bar,foo ,bazfoo '], File.readlines(tempname, chomp: true)2100 end2101 end21022103 def test_accept_nth_regex_delimiter2104 tmux.send_keys %(echo "foo :,:bar,baz" | #{FZF} --delimiter='[:,]+' --accept-nth 2,2,1,3,1 --sync --bind start:accept > #{tempname}), :Enter2104 tmux.send_keys %(echo "foo :,:bar,baz" | #{FZF} --delimiter=' *[:,]+ *' --accept-nth 2,2,1,3,1 --sync --bind start:accept > #{tempname}), :Enter2105 wait do2106 assert_path_exists tempname2107 # Last delimiter and the whitespaces are removed2108 assert_equal ['bar,bar,foo :,:bazfoo'], File.readlines(tempname, chomp: true)
9 unmodified lines
2118 end2119 end21202121 def test_accept_nth_template2122 tmux.send_keys %(echo "foo ,bar,baz" | #{FZF} -d, --accept-nth '[{n}] 1st: {1}, 3rd: {3}, 2nd: {2}' --sync --bind start:accept > #{tempname}), :Enter2122 tmux.send_keys %(echo "foo ,bar,baz" | #{FZF} -d " *, *" --accept-nth '[{n}] 1st: {1}, 3rd: {3}, 2nd: {2}' --sync --bind start:accept > #{tempname}), :Enter2123 wait do2124 assert_path_exists tempname2125 # Last delimiter and the whitespaces are removed2126 assert_equal ['[0] 1st: foo, 3rd: baz, 2nd: bar'], File.readlines(tempname, chomp: true)
330 unmodified lines