Add accept-or-print-query
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #3528
authored by Junegunn Choi · committed by Junegunn Choi · parent a343b20 · Browse files · 5 files·+49 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
5 files+49 added−0 removed
- tests:+29 added−0 removed
- other:+20 added−0 removed
Provenance
- Commit
c36a64b- Tree
66e6722- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
a343b20
5 files changed+49 added−0 removed
modified:man/man1/fzf.1+1 added
1118 unmodified lines1119 \fBACTION: DEFAULT BINDINGS (NOTES):1120 \fBabort\fR \fIctrl-c ctrl-g ctrl-q esc\fR1121 \fBaccept\fR \fIenter double-click\fR1122 \fBaccept-non-empty\fR (same as \fBaccept\fR except that it prevents fzf from exiting without selection)1123+ \fBaccept-or-print-query\fR (same as \fBaccept\fR except that it prints the query when there's no match)1124 \fBbackward-char\fR \fIctrl-b left\fR1125 \fBbackward-delete-char\fR \fIctrl-h bspace\fR1126 \fBbackward-delete-char/eof\fR (same as \fBbackward-delete-char\fR except aborts fzf if query is empty)1127 \fBbackward-kill-word\fR \fIalt-bs\fR242 unmodified linesmodified:src/options.go+2 added
1068 unmodified lines1069 case "accept":1070 appendAction(actAccept)1071 case "accept-non-empty":1072 appendAction(actAcceptNonEmpty)1073+ case "accept-or-print-query":1074+ appendAction(actAcceptOrPrintQuery)1075 case "print-query":1076 appendAction(actPrintQuery)1077 case "refresh-preview":1078 appendAction(actRefreshPreview)1083 unmodified linesmodified:src/terminal.go+7 added
341 unmodified lines342 actBeginningOfLine343 actAbort344 actAccept345 actAcceptNonEmpty346+ actAcceptOrPrintQuery347 actBackwardChar348 actBackwardDeleteChar349 actBackwardDeleteCharEOF350 actBackwardWord3146 unmodified lines3497 case actAcceptNonEmpty:3498 if len(t.selected) > 0 || t.merger.Length() > 0 || !t.reading && t.count == 0 {3499 req(reqClose)3500 }3501+ case actAcceptOrPrintQuery:3502+ if len(t.selected) > 0 || t.merger.Length() > 0 {3503+ req(reqClose)3504+ } else {3505+ req(reqPrintQuery)3506+ }3507 case actClearScreen:3508 req(reqFullRedraw)3509 case actClearQuery:3510 t.input = []rune{}552 unmodified linesmodified:test/test_go.rb+29 added
1774 unmodified lines1775 # fzf will exit anyway since input list is empty1776 assert_equal %w[foo], readonce.lines(chomp: true)1777 end1778 1779+ def test_accept_or_print_query_without_match1780+ tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query')}), :Enter1781+ tmux.until { |lines| assert_equal 1000, lines.match_count }1782+ tmux.send_keys 999991783+ tmux.until { |lines| assert_equal 0, lines.match_count }1784+ tmux.send_keys :Enter1785+ assert_equal %w[99999], readonce.lines(chomp: true)1786+ end1787+1788+ def test_accept_or_print_query_with_match1789+ tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query')}), :Enter1790+ tmux.until { |lines| assert_equal 1000, lines.match_count }1791+ tmux.send_keys '^99$'1792+ tmux.until { |lines| assert_equal 1, lines.match_count }1793+ tmux.send_keys :Enter1794+ assert_equal %w[99], readonce.lines(chomp: true)1795+ end1796+1797+ def test_accept_or_print_query_with_multi_selection1798+ tmux.send_keys %(seq 1000 | #{fzf('--bind enter:accept-or-print-query --multi')}), :Enter1799+ tmux.until { |lines| assert_equal 1000, lines.match_count }1800+ tmux.send_keys :BTab, :BTab, :BTab1801+ tmux.until { |lines| assert_equal 3, lines.select_count }1802+ tmux.send_keys 999991803+ tmux.until { |lines| assert_equal 0, lines.match_count }1804+ tmux.send_keys :Enter1805+ assert_equal %w[1 2 3], readonce.lines(chomp: true)1806+ end1807+1808 def test_preview_update_on_select1809 tmux.send_keys %(seq 10 | fzf -m --preview 'echo {+}' --bind a:toggle-all),1810 :Enter1811 tmux.until { |lines| assert_equal 10, lines.item_count }1760 unmodified linesmodified:CHANGELOG.md+10 added
1 CHANGELOG2 =========3 4+0.44.25+------6+- Added `accept-or-print-query` action that acts like `accept` but prints the7+ current query when there's no match for the query8+ ```sh9+ # You can make CTRL-R paste the current query when there's no match10+ export FZF_CTRL_R_OPTS='--bind enter:accept-or-print-query'11+ ```12+- Bug fixes13+14 0.44.115 ------16 - Fixed crash when preview window is hidden on `focus` event17 1762 unmodified lines