Add 'one' event
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #2629 Close #2494 Close #459
authored by Junegunn Choi · committed by Junegunn Choi · parent 1c7534f · Browse files · 6 files·+39 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
6 files+39 added−0 removed
- tests:+14 added−0 removed
- other:+25 added−0 removed
Provenance
- Commit
8ec917b- Tree
74d6f5e- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
1c7534f
6 files changed+39 added−0 removed
modified:man/man1/fzf.1+11 added
991 unmodified lines992 993 # Beware not to introduce an infinite loop994 seq 10 | fzf --bind 'focus:up' --cycle\fR995 .RE996+\fIone\fR997+.RS998+Triggered when there's only one match. \fBone:accept\fR binding is comparable999+to \fB--select-1\fR option, but the difference is that \fB--select-1\fR is only1000+effective before the interactive finder starts but \fBone\fR event is triggered1001+by the interactive finder.1002 1003+e.g.1004+ \fB# Automatically select the only match1005+ seq 10 | fzf --bind one:accept\fR1006+.RE1007+1008 \fIbackward-eof\fR1009 .RS1010 Triggered when the query string is already empty and you try to delete it1011 backward.251 unmodified linesmodified:src/tui/tui.go+1 added
91 unmodified lines92 BackwardEOF93 Start94 Load95 Focus96+ One97 98 AltBS99 100 AltUp614 unmodified linesmodified:src/options.go+2 added
620 unmodified lines621 case "load":622 add(tui.Load)623 case "focus":624 add(tui.Focus)625+ case "one":626+ add(tui.One)627 case "alt-enter", "alt-return":628 chords[tui.CtrlAltKey('m')] = key629 case "alt-space":630 chords[tui.AltKey(' ')] = key1433 unmodified linesmodified:src/terminal.go+6 added
930 unmodified lines931 // Try to keep the vertical position when the list shrinks932 t.cy = count - util.Min(count, t.maxItems()) + pos933 }934 }935+ if !t.reading && t.merger.Length() == 1 {936+ one := tui.One.AsEvent()937+ if _, prs := t.keymap[one]; prs {938+ t.eventChan <- one939+ }940+ }941 t.mutex.Unlock()942 t.reqBox.Set(reqInfo, nil)943 t.reqBox.Set(reqList, nil)944 }2680 unmodified linesmodified:test/test_go.rb+14 added
2700 unmodified lines2701 assert_equal 1000, lines.match_count2702 assert_equal '> 555', lines[index]2703 end2704 end2705+2706+ def test_one2707+ tmux.send_keys "seq 10 | #{FZF} --bind 'one:preview:echo {} is the only match'", :Enter2708+ tmux.send_keys '1'2709+ tmux.until do |lines|2710+ assert_equal 2, lines.match_count2711+ refute lines.any? { _1.include?('only match') }2712+ end2713+ tmux.send_keys '0'2714+ tmux.until do |lines|2715+ assert_equal 1, lines.match_count2716+ assert lines.any? { _1.include?('only match') }2717+ end2718+ end2719 end2720 2721 module TestShell2722 def setup481 unmodified linesmodified:CHANGELOG.md+5 added
1 unmodified line2 =========3 4 0.39.05 ------6+- Added `one` event that is triggered when there's only one match7+ ```sh8+ # Automatically select the only match9+ seq 10 | fzf --bind one:accept10+ ```11 - Added `--track` option that makes fzf track the current selection when the12 result list is updated. This can be useful when browsing logs using fzf with13 sorting disabled.14 ```sh1586 unmodified lines