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 - including hidden directories
fda() { 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 # fh - repeat history

4
fzf
View File

@ -347,7 +347,7 @@ class FZF
tokens << [line[b...e], true] tokens << [line[b...e], true]
index = e index = e
end end
tokens << [line[index..-1], false] tokens << [line[index..-1], false] if index < line.length
tokens.reject { |pair| pair.first.empty? } tokens.reject { |pair| pair.first.empty? }
end end
@ -829,6 +829,8 @@ class FZF
case w case w
when '' when ''
nil nil
when /^\^(.*)\$$/
Regexp.new('^' << sanitize(Regexp.escape $1) << '$', rxflag)
when /^'/ when /^'/
w.length > 1 ? w.length > 1 ?
Regexp.new(sanitize(Regexp.escape(w[1..-1])), rxflag) : nil 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, match.call('j', '').length
assert_equal list.length - 1, 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 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"], assert_equal ["a", "b", "c", "\xFF", "d", "e", "f"],
FZF::UConv.split("abc\xFFdef") FZF::UConv.split("abc\xFFdef")
end 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 end