diff --git a/CHANGELOG.md b/CHANGELOG.md index cc8c9c4..4ede76d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,12 +68,22 @@ CHANGELOG # Can only type numbers fzf --bind 'change:transform-query(sed 's/[^0-9]//g' <<< {q})' ``` -- Improvements - `put` action can optionally take an argument string ```sh # a will put 'alpha' on the prompt, ctrl-b will put 'bravo' fzf --bind 'a:put+put(lpha),ctrl-b:put(bravo)' ``` +- Behavior changes + - fzf will always execute the preview command if the command template + contains `{q}` even when it's empty. If you prefer the old behavior, + you'll have to check if `{q}` is empty in your command. + ```sh + # This will show // even when the query is empty + : | fzf --preview 'echo /{q}/' + + # But if you don't want it, + : | fzf --preview '[ -n {q} ] || exit; echo /{q}/' + ``` - `double-click` will behave the same as `enter` unless otherwise specified, so you don't have to repeat the same action twice in `--bind` in most cases. ```sh diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index 61d583f..2efde05 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -536,7 +536,8 @@ e.g. Note that you can escape a placeholder pattern by prepending a backslash. Preview window will be updated even when there is no match for the current -query if any of the placeholder expressions evaluates to a non-empty string. +query if any of the placeholder expressions evaluates to a non-empty string +or \fB{q}\fR is in the command template. Since 0.24.0, fzf can render partial preview content before the preview command completes. ANSI escape sequence for clearing the display (\fBCSI 2 J\fR) is diff --git a/src/terminal.go b/src/terminal.go index 7e900c9..72b2e00 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -2096,7 +2096,7 @@ func (t *Terminal) currentItem() *Item { func (t *Terminal) buildPlusList(template string, forcePlus bool) (bool, []*Item) { current := t.currentItem() slot, plus, query := hasPreviewFlags(template) - if !(!slot || query && len(t.input) > 0 || (forcePlus || plus) && len(t.selected) > 0) { + if !(!slot || query || (forcePlus || plus) && len(t.selected) > 0) { return current != nil, []*Item{current, current} } diff --git a/test/test_go.rb b/test/test_go.rb index 18999da..c7d62c7 100755 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -1555,13 +1555,13 @@ class TestGoFZF < TestBase end def test_preview_q_no_match - tmux.send_keys %(: | #{FZF} --preview 'echo foo {q}'), :Enter + tmux.send_keys %(: | #{FZF} --preview 'echo foo {q} foo'), :Enter tmux.until { |lines| assert_equal 0, lines.match_count } - tmux.until { |lines| refute_includes lines[1], ' foo ' } + tmux.until { |lines| assert_includes lines[1], ' foo foo' } tmux.send_keys 'bar' - tmux.until { |lines| assert_includes lines[1], ' foo bar ' } + tmux.until { |lines| assert_includes lines[1], ' foo bar foo' } tmux.send_keys 'C-u' - tmux.until { |lines| refute_includes lines[1], ' foo ' } + tmux.until { |lines| assert_includes lines[1], ' foo foo' } end def test_preview_q_no_match_with_initial_query