summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2016-01-14 01:32:03 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2016-01-14 01:32:03 +0900
commit45143f9541d55c5efdadc7ea8acd9474a19eb8c6 (patch)
tree27868cacf3ac2d9af9a18652f5150636bdbef308
parent23244bb41087f4f833c33219bba7a7213710ab20 (diff)
Ignore leading whitespaces when calculating 'begin' index
-rw-r--r--CHANGELOG.md3
-rw-r--r--src/item.go9
-rw-r--r--test/test_go.rb58
3 files changed, 68 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 87f78273..3d81d14d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
------
diff --git a/src/item.go b/src/item.go
index 9200efbf..43ce1a21 100644
--- a/src/item.go
+++ b/src/item.go
@@ -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)
diff --git a/test/test_go.rb b/test/test_go.rb
index a049a153..efbbf250 100644
--- a/test/test_go.rb
+++ b/test/test_go.rb
@@ -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