diff --git a/fzf b/fzf index 258d367..cad57bf 100755 --- a/fzf +++ b/fzf @@ -214,7 +214,7 @@ class FZF end class Matcher - def convert_query q + def query_chars q UConv.nfd(q).split(//) end end @@ -224,7 +224,7 @@ class FZF end class Matcher - def convert_query q + def query_chars q q.split(//) end end @@ -747,7 +747,7 @@ class FZF def fuzzy_regex q @regexp[q] ||= begin q = q.downcase if @rxflag != 0 - Regexp.new(convert_query(q).inject('') { |sum, e| + Regexp.new(query_chars(q).inject('') { |sum, e| e = Regexp.escape e sum << "#{e}[^#{e}]*?" }, @rxflag) @@ -804,13 +804,13 @@ class FZF nil when /^'/ w.length > 1 ? - Regexp.new(Regexp.escape(w[1..-1]), rxflag) : nil + Regexp.new(UConv.nfd(Regexp.escape(w[1..-1])), rxflag) : nil when /^\^/ w.length > 1 ? - Regexp.new('^' << Regexp.escape(w[1..-1]), rxflag) : nil + Regexp.new('^' << UConv.nfd(Regexp.escape(w[1..-1])), rxflag) : nil when /\$$/ w.length > 1 ? - Regexp.new(Regexp.escape(w[0..-2]) << '$', rxflag) : nil + Regexp.new(UConv.nfd(Regexp.escape(w[0..-2])) << '$', rxflag) : nil else fuzzy_regex w end, invert ] diff --git a/fzf.gemspec b/fzf.gemspec index 3f3d2bb..a6845df 100644 --- a/fzf.gemspec +++ b/fzf.gemspec @@ -1,7 +1,7 @@ # coding: utf-8 Gem::Specification.new do |spec| spec.name = 'fzf' - spec.version = '0.4.0' + spec.version = '0.4.1' spec.authors = ['Junegunn Choi'] spec.email = ['junegunn.c@gmail.com'] spec.description = %q{Fuzzy finder for your shell} diff --git a/test/test_fzf.rb b/test/test_fzf.rb index 6bff944..7d0f447 100644 --- a/test/test_fzf.rb +++ b/test/test_fzf.rb @@ -296,6 +296,21 @@ class TestFZF < MiniTest::Unit::TestCase assert_equal 6, nfd.length assert_equal NFD, nfd end + + def test_nfd_fuzzy_matcher + matcher = FZF::FuzzyMatcher.new 0 + match = matcher.match([NFD], '할', '', '') + assert_equal [[NFD, [[0, 6]]]], match + assert_equal ['한글', [[0, 2]]], FZF::UConv.nfc(*match.first) + end + + def test_nfd_extended_fuzzy_matcher + matcher = FZF::ExtendedFuzzyMatcher.new 0 + assert_equal [], matcher.match([NFD], "'할", '', '') + match = matcher.match([NFD], "'한글", '', '') + assert_equal [[NFD, [[0, 6]]]], match + assert_equal ['한글', [[0, 2]]], FZF::UConv.nfc(*match.first) + end end def test_split