Add exact-match and invert-exact-match match types
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 76c7f4f · Browse files · 3 files·+35 added−12 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+35 added−12 removed
- tests:+8 added−0 removed
- other:+27 added−12 removed
Provenance
- Commit
e4a49db- Tree
7f47c0c- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
76c7f4f
3 files changed+35 added−12 removed
modified:test/test_fzf.rb+8 added
192 unmodified lines193 assert_equal list.length - 1, match.call('!l$', '').length194 195 # ! + f196 assert_equal [["juicy", [[4, 5]]]], match.call('y !l', '')197+198+ # '199+ assert_equal %w[juiceful juiceless juicily],200+ match.call('il', '').map { |e| e.first }201+ assert_equal %w[juicily],202+ match.call("'il", '').map { |e| e.first }203+ assert_equal (list - %w[juicily]).sort,204+ match.call("!'il", '').map { |e| e.first }.sort205 end206 assert !matcher.caches.empty?207 end208 97 unmodified linesmodified:fzf+18 added-5 removed
547 unmodified lines548 @sort ? found : found.reverse549 end)550 551 mcount = @matches.length552- if @sort && mcount <= @sort && !q.empty?552+ if @sort && mcount <= @sort && !matcher.empty?(q)553 @matches.set { |m| sort_by_rank m }554 end555 end#new_search556 139 unmodified lines696 @regexp = {}697 @rxflag = rxflag698 end699 700+ def empty? q701+ q.empty?702+ end703+704 def fuzzy_regex q705 @regexp[q] ||= begin706 q = q.downcase if @rxflag != 0707 Regexp.new(convert_query(q).inject('') { |sum, e|34 unmodified lines742 require 'set'743 @regexps = {}744 end745 742- def match list, q, prefix, suffix743- q = q.strip746+ def empty? q747+ parse(q).empty?748+ end749 750+ def parse q751+ q = q.strip745- regexps = @regexps[q] ||= q.split(/\s+/).map { |w|752+ @regexps[q] ||= q.split(/\s+/).map { |w|753 invert =754 if w =~ /^!/755 w = w[1..-1]756 true2 unmodified lines759 [ @regexp[w] ||=760 case w761 when ''762 nil763+ when /^'/764+ w.length > 1 ?765+ Regexp.new(Regexp.escape(w[1..-1]), rxflag) : nil766 when /^\^/767 w.length > 1 ?768 Regexp.new('^' << Regexp.escape(w[1..-1]), rxflag) : nil769 when /\$$/2 unmodified lines772 else773 fuzzy_regex w774 end, invert ]775 }.select { |pair| pair.first }776+ end777 778+ def match list, q, prefix, suffix779+ regexps = parse q780 # Look for prefix cache781 cache = @caches[list.object_id]769- prefix = prefix.strip.sub(/\$\S+$/, '').sub(/!\S+$/, '')782+ prefix = prefix.strip.sub(/\$\S*$/, '').sub(/(^|\s)!\S*$/, '')783 prefix_cache = nil784 (prefix.length - 1).downto(1) do |len|785 break if prefix_cache = cache[Set[@regexps[prefix[0, len]]]]786 end21 unmodified linesmodified:README.md+9 added-7 removed
112 unmodified lines113 114 If you enable multi-select mode with `-m` option, you can select multiple items115 with TAB or Shift-TAB key.116 117-### Extended mode117+### Extended mode (WIP)118 119 With `-x` or `--extended` option, fzf will start in "extended mode".120 121 In extended mode, you can specify multiple patterns delimited by spaces, such as: `^music .mp3$ sbtrkt !rmx`122 123-| Token | Description | Match type |124-| -------- | ----------------------------- | -------------------- |125-| `^music` | Items that start with `music` | prefix-exact-match |126-| `.mp3$` | Items that end with `.mp3` | suffix-exact-match |127-| `sbtrkt` | Items that match `sbtrkt` | fuzzy-match |128-| `!rmx` | Items that do not match `rmx` | invert-fuzzy-match |123+| Token | Description | Match type |124+| ----------- | -------------------------------- | -------------------- |125+| `^music` | Items that start with `music` | prefix-exact-match |126+| `.mp3$` | Items that end with `.mp3` | suffix-exact-match |127+| `sbtrkt` | Items that match `sbtrkt` | fuzzy-match |128+| `!rmx` | Items that do not match `rmx` | invert-fuzzy-match |129+| `'wild` | Items that include `wild` | exact-match |130+| `!'fire` | Items that do not include `fire` | invert-exact-match |131 132 Usage as Vim plugin133 -------------------134 131 unmodified lines