Add 'next-selected' and 'prev-selected' actions
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #2749
authored by Junegunn Choi · committed by Junegunn Choi · parent 0ad3006 · Browse files · 5 files·+54 added−1 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+54 added−1 removed
- tests:+19 added−0 removed
- other:+35 added−1 removed
Provenance
- Commit
18e3b38- Tree
8ed4829- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
0ad3006
5 files changed+54 added−1 removed
modified:man/man1/fzf.1+2 added
972 unmodified lines973 \fBkill-line\fR974 \fBkill-word\fR \fIalt-d\fR975 \fBlast\fR (move to the last match)976 \fBnext-history\fR (\fIctrl-n\fR on \fB--history\fR)977+ \fBnext-selected\fR (move to the next selected item)978 \fBpage-down\fR \fIpgdn\fR979 \fBpage-up\fR \fIpgup\fR980 \fBhalf-page-down\fR981 \fBhalf-page-up\fR982 \fBprev-history\fR (\fIctrl-p\fR on \fB--history\fR)983+ \fBprev-selected\fR (move to the previous selected item)984 \fBpreview(...)\fR (see below for the details)985 \fBpreview-down\fR \fIshift-down\fR986 \fBpreview-up\fR \fIshift-up\fR987 \fBpreview-page-down\fR161 unmodified linesmodified:src/options.go+4 added
1062 unmodified lines1063 case "prev-history", "previous-history":1064 appendAction(actPrevHistory)1065 case "next-history":1066 appendAction(actNextHistory)1067+ case "prev-selected":1068+ appendAction(actPrevSelected)1069+ case "next-selected":1070+ appendAction(actNextSelected)1071 case "toggle-preview":1072 appendAction(actTogglePreview)1073 case "toggle-preview-wrap":1074 appendAction(actTogglePreviewWrap)869 unmodified linesmodified:src/terminal.go+18 added
314 unmodified lines315 actPreviewPageDown316 actPreviewHalfPageUp317 actPreviewHalfPageDown318 actPrevHistory319+ actPrevSelected320 actNextHistory321+ actNextSelected322 actExecute323 actExecuteSilent324 actExecuteMulti // Deprecated325 actSigStop2691 unmodified lines3017 if t.hasPreviewWindow() && currentPreviewOpts.scroll != t.previewOpts.scroll {3018 scrollPreviewTo(t.evaluateScrollOffset())3019 }3020 }3021+ case actNextSelected, actPrevSelected:3022+ if len(t.selected) > 0 {3023+ total := t.merger.Length()3024+ for i := 1; i < total; i++ {3025+ y := (t.cy + i) % total3026+ if t.layout == layoutDefault && a.t == actNextSelected ||3027+ t.layout != layoutDefault && a.t == actPrevSelected {3028+ y = (t.cy - i + total) % total3029+ }3030+ if _, found := t.selected[t.merger.Get(y).item.Index()]; found {3031+ t.vset(y)3032+ req(reqList)3033+ break3034+ }3035+ }3036+ }3037 }3038 return true3039 }3040 119 unmodified linesmodified:test/test_go.rb+19 added
2406 unmodified lines2407 def test_info_no_separator2408 tmux.send_keys 'seq 100 | fzf -q55 --no-separator', :Enter2409 tmux.until { assert(_1[-2] == ' 1/100') }2410 end2411+2412+ def test_prev_next_selected2413+ tmux.send_keys 'seq 10 | fzf --multi --bind ctrl-n:next-selected,ctrl-p:prev-selected', :Enter2414+ tmux.until { |lines| assert_equal 10, lines.item_count }2415+ tmux.send_keys :BTab, :BTab, :Up, :BTab2416+ tmux.until { |lines| assert_equal 3, lines.select_count }2417+ tmux.send_keys 'C-n'2418+ tmux.until { |lines| assert_includes lines, '>>4' }2419+ tmux.send_keys 'C-n'2420+ tmux.until { |lines| assert_includes lines, '>>2' }2421+ tmux.send_keys 'C-n'2422+ tmux.until { |lines| assert_includes lines, '>>1' }2423+ tmux.send_keys 'C-n'2424+ tmux.until { |lines| assert_includes lines, '>>4' }2425+ tmux.send_keys 'C-p'2426+ tmux.until { |lines| assert_includes lines, '>>1' }2427+ tmux.send_keys 'C-p'2428+ tmux.until { |lines| assert_includes lines, '>>2' }2429+ end2430 end2431 2432 module TestShell2433 def setup479 unmodified linesmodified:CHANGELOG.md+11 added-1 removed
1 CHANGELOG2 =========3 4-0.35.24+0.36.05 ------6+- Added `next-selected` and `prev-selected` actions to move between selected7+ items8+ ```sh9+ # `next-selected` will move the pointer to the next selected item below the current line10+ # `prev-selected` will move the pointer to the previous selected item above the current line11+ seq 10 | fzf --multi --bind ctrl-n:next-selected,ctrl-p:prev-selected12+13+ # Both actions respect --layout option14+ seq 10 | fzf --multi --bind ctrl-n:next-selected,ctrl-p:prev-selected --layout reverse15+ ```16 - `double-click` will behave the same as `enter` unless otherwise specified,17 so you don't have to repeat the same action twice in `--bind` in most cases.18 ```sh19 # No need to bind 'double-click' to the same action1395 unmodified lines