Skip to content
Myr

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

3 files+35 added−12 removed

modified:test/test_fzf.rb+8 added
192 unmodified lines
193 assert_equal list.length - 1, match.call('!l$', '').length194195 # ! + f196 assert_equal [["juicy", [[4, 5]]]], match.call('y !l', '')197198 # '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 lines
modified:fzf+18 added-5 removed
547 unmodified lines
548 @sort ? found : found.reverse549 end)550551 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 lines
696 @regexp = {}697 @rxflag = rxflag698 end699700 def empty? q701 q.empty?702 end703704 def fuzzy_regex q705 @regexp[q] ||= begin706 q = q.downcase if @rxflag != 0707 Regexp.new(convert_query(q).inject('') { |sum, e|
34 unmodified lines
742 require 'set'743 @regexps = {}744 end745742 def match list, q, prefix, suffix743 q = q.strip746 def empty? q747 parse(q).empty?748 end749750 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 true
2 unmodified lines
759 [ @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 lines
772 else773 fuzzy_regex w774 end, invert ]775 }.select { |pair| pair.first }776 end777778 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 end
21 unmodified lines
modified:README.md+9 added-7 removed
112 unmodified lines
113114If you enable multi-select mode with `-m` option, you can select multiple items115with TAB or Shift-TAB key.116117### Extended mode117### Extended mode (WIP)118119With `-x` or `--extended` option, fzf will start in "extended mode".120121In extended mode, you can specify multiple patterns delimited by spaces, such as: `^music .mp3$ sbtrkt !rmx`122123| 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 |131132Usage as Vim plugin133-------------------134
131 unmodified lines