Add 'zero' event
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #3263
authored by Junegunn Choi · committed by Junegunn Choi · parent 65dd2bb · Browse files · 6 files·+49 added−7 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+49 added−7 removed
- tests:+8 added−2 removed
- other:+41 added−5 removed
Provenance
- Commit
cf95e44- Tree
58d0c5b- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
65dd2bb
6 files changed+49 added−7 removed
modified:man/man1/fzf.1+11 added
1006 unmodified lines1007 e.g.1008 \fB# Automatically select the only match1009 seq 10 | fzf --bind one:accept\fR1010 .RE1011+\fIzero\fR1012+.RS1013+Triggered when there's no match. \fBzero:abort\fR binding is comparable to1014+\fB--exit-0\fR option, but the difference is that \fB--exit-0\fR is only1015+effective before the interactive finder starts but \fBzero\fR event is1016+triggered by the interactive finder.1017 1018+e.g.1019+ \fB# Reload the candidate list when there's no match1020+ echo $RANDOM | fzf --bind 'zero:reload(echo $RANDOM)+clear-query' --height 3\fR1021+.RE1022+1023 \fIbackward-eof\fR1024 .RS1025 Triggered when the query string is already empty and you try to delete it1026 backward.255 unmodified linesmodified:src/tui/tui.go+10 added
92 unmodified lines93 Start94 Load95 Focus96 One97+ Zero98 99 AltBS100 101 AltUp181 unmodified lines283 Char rune284 MouseEvent *MouseEvent285 }286 287+func (e Event) Is(types ...EventType) bool {288+ for _, t := range types {289+ if e.Type == t {290+ return true291+ }292+ }293+ return false294+}295+296 type MouseEvent struct {297 Y int298 X int299 S int425 unmodified linesmodified:src/options.go+2 added
630 unmodified lines631 case "focus":632 add(tui.Focus)633 case "one":634 add(tui.One)635+ case "zero":636+ add(tui.Zero)637 case "alt-enter", "alt-return":638 chords[tui.CtrlAltKey('m')] = key639 case "alt-space":640 chords[tui.AltKey(' ')] = key1441 unmodified linesmodified:src/terminal.go+13 added-5 removed
954 unmodified lines955 // Try to keep the vertical position when the list shrinks956 t.cy = count - util.Min(count, t.maxItems()) + pos957 }958 }959+ if !t.reading {960+ switch t.merger.Length() {961+ case 0:962+ zero := tui.Zero.AsEvent()963+ if _, prs := t.keymap[zero]; prs {964+ t.eventChan <- zero965+ }959- if !t.reading && t.merger.Length() == 1 {960- one := tui.One.AsEvent()961- if _, prs := t.keymap[one]; prs {962- t.eventChan <- one966+ case 1:967+ one := tui.One.AsEvent()968+ if _, prs := t.keymap[one]; prs {969+ t.eventChan <- one970+ }971 }972 }973 t.mutex.Unlock()974 t.reqBox.Set(reqInfo, nil)1886 unmodified lines2861 barrier <- true2862 }2863 select {2864 case event = <-t.eventChan:2857- needBarrier = event != tui.Load.AsEvent()2865+ needBarrier = !event.Is(tui.Load, tui.One, tui.Zero)2866 case actions = <-t.serverChan:2867 event = tui.Invalid.AsEvent()2868 needBarrier = false2869 }825 unmodified linesmodified:test/test_go.rb+8 added-2 removed
2833 unmodified lines2834 refute_includes lines[-2], '+T'2835 end2836 end2837 2838- def test_one2839- tmux.send_keys "seq 10 | #{FZF} --bind 'one:preview:echo {} is the only match'", :Enter2838+ def test_one_and_zero2839+ tmux.send_keys "seq 10 | #{FZF} --bind 'zero:preview(echo no match),one:preview(echo {} is the only match)'", :Enter2840 tmux.send_keys '1'2841 tmux.until do |lines|2842 assert_equal 2, lines.match_count2843 refute(lines.any? { _1.include?('only match') })2844+ refute(lines.any? { _1.include?('no match') })2845 end2846 tmux.send_keys '0'2847 tmux.until do |lines|2848 assert_equal 1, lines.match_count2849 assert(lines.any? { _1.include?('only match') })2850 end2851+ tmux.send_keys '0'2852+ tmux.until do |lines|2853+ assert_equal 0, lines.match_count2854+ assert(lines.any? { _1.include?('no match') })2855+ end2856 end2857 2858 def test_height_range_with_exit_02859 tmux.send_keys "seq 10 | #{FZF} --height ~10% --exit-0", :Enter489 unmodified linesmodified:CHANGELOG.md+5 added
1 unmodified line2 =========3 4 0.40.05 ------6+- Added `zero` event that is triggered when there's no match7+ ```sh8+ # Reload the candidate list when there's no match9+ echo $RANDOM | fzf --bind 'zero:reload(echo $RANDOM)+clear-query' --height 310+ ```11 - New actions12 - Added `track` action which makes fzf track the current item when the13 search result is updated. If the user manually moves the cursor, or the14 item is not in the updated search result, tracking is automatically1618 unmodified lines