Ignore leading whitespaces when calculating 'begin' index

pull/486/head
Junegunn Choi 8 years ago
parent 23244bb410
commit 45143f9541

@ -4,11 +4,12 @@ CHANGELOG
0.11.2
------
- `--tiebreak` now accepts comma-separated list of sort criteria.
- `--tiebreak` now accepts comma-separated list of sort criteria
- Each criterion should appear only once in the list
- `index` is only allowed at the end of the list
- `index` is implicitly appended to the list when not specified
- Default is `length` (or equivalently `length,index`)
- `begin` criterion will ignore leading whitespaces when calculating the index
0.11.1
------

@ -92,7 +92,14 @@ func (item *Item) Rank(cache bool) [5]int32 {
}
case byBegin:
// We can't just look at item.offsets[0][0] because it can be an inverse term
val = int32(minBegin)
whitePrefixLen := 0
for idx, r := range item.text {
whitePrefixLen = idx
if idx == minBegin || r != ' ' && r != '\t' {
break
}
}
val = int32(minBegin - whitePrefixLen)
case byEnd:
if prevEnd > 0 {
val = int32(1 + len(item.text) - prevEnd)

@ -605,6 +605,64 @@ class TestGoFZF < TestBase
assert_equal by_begin_end, `#{FZF} -ffb --tiebreak=end,length < #{tempname}`.split($/)
end
def test_tiebreak_white_prefix
writelines tempname, [
'f o o b a r',
' foo bar',
' foobar',
'----foo bar',
'----foobar',
' foo bar',
' foobar--',
' foobar',
'--foo bar',
'--foobar',
'foobar',
]
assert_equal [
' foobar',
' foobar',
'foobar',
' foobar--',
'--foobar',
'----foobar',
' foo bar',
' foo bar',
'--foo bar',
'----foo bar',
'f o o b a r',
], `#{FZF} -ffb < #{tempname}`.split($/)
assert_equal [
' foobar',
' foobar--',
' foobar',
'foobar',
'--foobar',
'----foobar',
' foo bar',
' foo bar',
'--foo bar',
'----foo bar',
'f o o b a r',
], `#{FZF} -ffb --tiebreak=begin < #{tempname}`.split($/)
assert_equal [
' foobar',
' foobar',
'foobar',
' foobar--',
'--foobar',
'----foobar',
' foo bar',
' foo bar',
'--foo bar',
'----foo bar',
'f o o b a r',
], `#{FZF} -ffb --tiebreak=begin,length < #{tempname}`.split($/)
end
def test_tiebreak_length_with_nth
input = %w[
1:hell

Loading…
Cancel
Save