From f0bfeba733f755a81b2e2d327268f2dabae8f684 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 2 Aug 2022 13:44:55 +0900 Subject: Add new tiebreak: 'chunk' Favors the line with shorter matched chunk. A chunk is a set of consecutive non-whitespace characters. Unlike the default `length`, this new scheme works well with tabular input. # length prefers item #1, because the whole line is shorter, # chunk prefers item #2, because the matched chunk ("foo") is shorter fzf --height=6 --header-lines=2 --tiebreak=chunk --reverse --query=fo << "EOF" N | Field1 | Field2 | Field3 - | ------ | ------ | ------ 1 | hello | foobar | baz 2 | world | foo | bazbaz EOF If the input does not contain any spaces, `chunk` is equivalent to `length`. But we're not going to set it as the default because it is computationally more expensive. Close #2285 Close #2537 - Not the exact solution to --tiebreak=length not taking --nth into account, but this should work. And the added benefit is that it works well even when --nth is not provided. - Adding a bonus point to the last character of a word didn't turn out great. The order of the result suddenly changes when you type in the last character in the word producing a jarring effect. --- test/test_go.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test') diff --git a/test/test_go.rb b/test/test_go.rb index d64df315..aa549ad3 100755 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -754,6 +754,20 @@ class TestGoFZF < TestBase assert_equal output, `#{FZF} -fh -n2 -d: < #{tempname}`.lines(chomp: true) end + def test_tiebreak_chunk + writelines(tempname, [ + '1 foobarbaz baz', + '2 foobar baz', + '3 foo barbaz' + ]) + + assert_equal [ + '3 foo barbaz', + '2 foobar baz', + '1 foobarbaz baz' + ], `#{FZF} -fo --tiebreak=chunk < #{tempname}`.lines(chomp: true) + end + def test_invalid_cache tmux.send_keys "(echo d; echo D; echo x) | #{fzf('-q d')}", :Enter tmux.until { |lines| assert_equal ' 2/3', lines[-2] } -- cgit v1.2.3