Add accept-non-empty action
Before adoption: this commit came in with the history the project adopted, so no landing records it.
'accept-non-empty' is similar to 'accept' (which is bound to 'enter' and 'double-click' by default) but it prevents fzf from exiting without any selection. Close #1162
authored by Junegunn Choi · committed by Junegunn Choi · parent 338a73d · Browse files · 4 files·+44 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+44 added−0 removed
- tests:+36 added−0 removed
- other:+8 added−0 removed
Provenance
- Commit
5a7b41a- Tree
161dfd4- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
338a73d
4 files changed+44 added−0 removed
modified:man/man1/fzf.1+1 added
490 unmodified lines491 492 \fBACTION: DEFAULT BINDINGS (NOTES):493 \fBabort\fR \fIctrl-c ctrl-g ctrl-q esc\fR494 \fBaccept\fR \fIenter double-click\fR495+ \fBaccept-non-empty\fR (same as \fBaccept\fR except that it prevents fzf from exiting without selection)496 \fBbackward-char\fR \fIctrl-b left\fR497 \fBbackward-delete-char\fR \fIctrl-h bspace\fR498 \fBbackward-kill-word\fR \fIalt-bs\fR499 \fBbackward-word\fR \fIalt-b shift-left\fR107 unmodified linesmodified:src/options.go+2 added
660 unmodified lines661 case "abort":662 appendAction(actAbort)663 case "accept":664 appendAction(actAccept)665+ case "accept-non-empty":666+ appendAction(actAcceptNonEmpty)667 case "print-query":668 appendAction(actPrintQuery)669 case "replace-query":670 appendAction(actReplaceQuery)593 unmodified linesmodified:src/terminal.go+5 added
168 unmodified lines169 actMouse170 actBeginningOfLine171 actAbort172 actAccept173+ actAcceptNonEmpty174 actBackwardChar175 actBackwardDeleteChar176 actBackwardWord177 actCancel1478 unmodified lines1656 t.vmove(1, true)1657 req(reqList)1658 case actAccept:1659 req(reqClose)1660+ case actAcceptNonEmpty:1661+ if len(t.selected) > 0 || t.merger.Length() > 0 || !t.reading && t.count == 0 {1662+ req(reqClose)1663+ }1664 case actClearScreen:1665 req(reqRedraw)1666 case actTop:1667 t.vset(0)220 unmodified linesmodified:test/test_go.rb+36 added
1376 unmodified lines1377 tmux.until { |lines| lines[-3] == '> 11' }1378 tmux.send_keys :Enter1379 end1380 1381+ def test_accept_non_empty1382+ tmux.send_keys %(seq 1000 | #{fzf '--print-query --bind enter:accept-non-empty'}), :Enter1383+ tmux.until { |lines| lines.match_count == 1000 }1384+ tmux.send_keys 'foo'1385+ tmux.until { |lines| lines[-2].include? '0/1000' }1386+ # fzf doesn't exit since there's no selection1387+ tmux.send_keys :Enter1388+ tmux.until { |lines| lines[-2].include? '0/1000' }1389+ tmux.send_keys 'C-u'1390+ tmux.until { |lines| lines[-2].include? '1000/1000' }1391+ tmux.send_keys '999'1392+ tmux.until { |lines| lines[-2].include? '1/1000' }1393+ tmux.send_keys :Enter1394+ assert_equal %w[999 999], readonce.split($INPUT_RECORD_SEPARATOR)1395+ end1396+1397+ def test_accept_non_empty_with_multi_selection1398+ tmux.send_keys %(seq 1000 | #{fzf '-m --print-query --bind enter:accept-non-empty'}), :Enter1399+ tmux.until { |lines| lines.match_count == 1000 }1400+ tmux.send_keys :Tab1401+ tmux.until { |lines| lines[-2].include? '1000/1000 (1)' }1402+ tmux.send_keys 'foo'1403+ tmux.until { |lines| lines[-2].include? '0/1000' }1404+ # fzf will exit in this case even though there's no match for the current query1405+ tmux.send_keys :Enter1406+ assert_equal %w[foo 1], readonce.split($INPUT_RECORD_SEPARATOR)1407+ end1408+1409+ def test_accept_non_empty_with_empty_list1410+ tmux.send_keys %(: | #{fzf '-q foo --print-query --bind enter:accept-non-empty'}), :Enter1411+ tmux.until { |lines| lines[-2].strip == '0/0' }1412+ tmux.send_keys :Enter1413+ # fzf will exit anyway since input list is empty1414+ assert_equal %w[foo], readonce.split($INPUT_RECORD_SEPARATOR)1415+ end1416+1417 def test_preview_update_on_select1418 tmux.send_keys(%(seq 10 | fzf -m --preview 'echo {+}' --bind a:toggle-all),1419 :Enter)1420 tmux.until { |lines| lines.item_count == 10 }380 unmodified lines