Fix ^.*$ pattern matching in extended-search mode (#9)

This commit is contained in:
Junegunn Choi 2013-12-09 14:46:06 +09:00
parent 04ebaddf5e
commit cb3645ea95
3 changed files with 18 additions and 2 deletions

View File

@ -189,7 +189,7 @@ fd() {
# fda - including hidden directories
fda() {
DIR=$(find ${1:-*} -type d 2> /dev/null | fzf) && cd "$DIR"
DIR=$(find ${1:-.} -type d 2> /dev/null | fzf) && cd "$DIR"
}
# fh - repeat history

4
fzf
View File

@ -347,7 +347,7 @@ class FZF
tokens << [line[b...e], true]
index = e
end
tokens << [line[index..-1], false]
tokens << [line[index..-1], false] if index < line.length
tokens.reject { |pair| pair.first.empty? }
end
@ -829,6 +829,8 @@ class FZF
case w
when ''
nil
when /^\^(.*)\$$/
Regexp.new('^' << sanitize(Regexp.escape $1) << '$', rxflag)
when /^'/
w.length > 1 ?
Regexp.new(sanitize(Regexp.escape(w[1..-1])), rxflag) : nil

View File

@ -197,6 +197,11 @@ class TestFZF < MiniTest::Unit::TestCase
assert_equal list.length, match.call('j', '').length
assert_equal list.length - 1, match.call('^j', '').length
# ^ + $
assert_equal 0, match.call('^juici$', '').length
assert_equal 1, match.call('^juice$', '').length
assert_equal 0, match.call('^.*$', '').length
# !
assert_equal 0, match.call('!j', '').length
@ -332,5 +337,14 @@ class TestFZF < MiniTest::Unit::TestCase
assert_equal ["a", "b", "c", "\xFF", "d", "e", "f"],
FZF::UConv.split("abc\xFFdef")
end
# ^$ -> matches empty item
def test_format_empty_item
fzf = FZF.new []
item = ['', [[0, 0]]]
line, offsets = fzf.convert_item item
tokens = fzf.format line, 80, offsets
assert_equal [], tokens
end
end