Skip to content
Myr

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

6 files+49 added−7 removed

modified:man/man1/fzf.1+11 added
1006 unmodified lines
1007e.g.1008 \fB# Automatically select the only match1009 seq 10 | fzf --bind one:accept\fR1010.RE1011\fIzero\fR1012.RS1013Triggered 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 only1015effective before the interactive finder starts but \fBzero\fR event is1016triggered by the interactive finder.10171018e.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.RE10221023\fIbackward-eof\fR1024.RS1025Triggered when the query string is already empty and you try to delete it1026backward.
255 unmodified lines
modified:src/tui/tui.go+10 added
92 unmodified lines
93 Start94 Load95 Focus96 One97 Zero9899 AltBS100101 AltUp
181 unmodified lines
283 Char rune284 MouseEvent *MouseEvent285}286287func (e Event) Is(types ...EventType) bool {288 for _, t := range types {289 if e.Type == t {290 return true291 }292 }293 return false294}295296type MouseEvent struct {297 Y int298 X int299 S int
425 unmodified lines
modified:src/options.go+2 added
630 unmodified lines
631 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(' ')] = key
1441 unmodified lines
modified:src/terminal.go+13 added-5 removed
954 unmodified lines
955 // 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 lines
2861 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 lines
modified:test/test_go.rb+8 added-2 removed
2833 unmodified lines
2834 refute_includes lines[-2], '+T'2835 end2836 end28372838 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 end28572858 def test_height_range_with_exit_02859 tmux.send_keys "seq 10 | #{FZF} --height ~10% --exit-0", :Enter
489 unmodified lines
modified:CHANGELOG.md+5 added
1 unmodified line
2=========340.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 automatically
1618 unmodified lines