Skip to content
Myr

Smart match of accented characters

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

Fix #1618

authored by Junegunn Choi · committed by Junegunn Choi · parent aa5dae3 · Browse files · 3 files+21 added−3 removed
This commit

State

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

Diff stats

3 files+21 added−3 removed

  • tests:+8 added−0 removed
  • other:+13 added−3 removed

3 files+21 added−3 removed

modified:src/pattern.go+9 added-3 removed
31 unmodified lines
32 typ termType33 inv bool34 text []rune35 caseSensitive bool36 normalize bool37}3839// String returns the string representation of a term.40func (t term) String() string {
87 unmodified lines
128 }129 }130 } else {131 lowerString := strings.ToLower(asString)132 normalize = normalize &&133 lowerString == string(algo.NormalizeRunes([]rune(lowerString)))134 caseSensitive = caseMode == CaseRespect ||135 caseMode == CaseSmart && lowerString != asString136 if !caseSensitive {137 asString = lowerString
37 unmodified lines
175 typ, inv, text := termFuzzy, false, strings.Replace(token, "\t", " ", -1)176 lowerText := strings.ToLower(text)177 caseSensitive := caseMode == CaseRespect ||178 caseMode == CaseSmart && text != lowerText179 normalizeTerm := normalize &&180 lowerText == string(algo.NormalizeRunes([]rune(lowerText)))181 if !caseSensitive {182 text = lowerText183 }184 if !fuzzy {
41 unmodified lines
226 sets = append(sets, set)227 set = termSet{}228 }229 textRunes := []rune(text)225 if normalize {230 if normalizeTerm {231 textRunes = algo.NormalizeRunes(textRunes)232 }233 set = append(set, term{234 typ: typ,235 inv: inv,236 text: textRunes,232 caseSensitive: caseSensitive})237 caseSensitive: caseSensitive,238 normalize: normalizeTerm})239 switchSet = true240 }241 }242 if len(set) > 0 {
122 unmodified lines
365 var currentScore int366 matched := false367 for _, term := range termSet {368 pfun := p.procFun[term.typ]363 off, score, pos := p.iter(pfun, input, term.caseSensitive, p.normalize, p.forward, term.text, withPos, slab)369 off, score, pos := p.iter(pfun, input, term.caseSensitive, term.normalize, p.forward, term.text, withPos, slab)370 if sidx := off[0]; sidx >= 0 {371 if term.inv {372 continue373 }
52 unmodified lines
modified:test/test_go.rb+8 added
1803 unmodified lines
1804 tmux.send_keys "echo foo 123 321 | #{FZF} --preview 'seq 1000' --preview-window left:+{2}-2", :Enter1805 tmux.until { |lines| lines.item_count == 1 }1806 tmux.until { |lines| assert_match %r{121.*121/1000}, lines[1] }1807 end18081809 def test_normalized_match1810 echoes = '(echo a; echo á; echo A; echo Á;)'1811 assert_equal %w[a á A Á], `#{echoes} | #{FZF} -f a`.lines.map(&:chomp)1812 assert_equal %w[á Á], `#{echoes} | #{FZF} -f á`.lines.map(&:chomp)1813 assert_equal %w[A Á], `#{echoes} | #{FZF} -f A`.lines.map(&:chomp)1814 assert_equal %w[Á], `#{echoes} | #{FZF} -f Á`.lines.map(&:chomp)1815 end1816end18171818module TestShell1819 def setup
475 unmodified lines
modified:CHANGELOG.md+4 added
32 unmodified lines
33 git grep --line-number '' |34 fzf --delimiter : --preview 'nl {1}' --preview-window +{2}-535 ```36- Added support for ANSI colors in `--prompt` string37- Smart match of accented characters38 - An unaccented character in the query string will match both accented and39 unaccented characters, while an accented character will only match40 accented characters. This is similar to how "smart-case" match works.41- Vim plugin42 - `tmux` layout option for using fzf-tmux43 ```vim44 let g:fzf_layout = { 'tmux': '-p90%,60%' }
869 unmodified lines