Skip to content
Myr

Add jump and jump-cancel events

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Close #3412 # Default behavior fzf --bind space:jump # Same as jump-accept action fzf --bind space:jump,jump:accept # Accept on jump, abort on cancel fzf --bind space:jump,jump:accept,jump-cancel:abort # Change header on jump-cancel fzf --bind 'space:change-header(Type jump label)+jump,jump-cancel:change-header:Jump cancelled'

authored by Junegunn Choi · committed by Junegunn Choi · parent 17bb7ad · Browse files · 5 files+52 added−8 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+52 added−8 removed

  • tests:+13 added−0 removed
  • other:+39 added−8 removed

5 files+52 added−8 removed

modified:man/man1/fzf.1+21 added
1158 unmodified lines
1159e.g.1160 \fB# Move cursor to the last item and select all items1161 seq 1000 | fzf --multi --sync --bind start:last+select-all\fR1162.RE11631164\fIload\fR1165.RS1166Triggered when the input stream is complete and the initial processing of the1167list is complete.
1 unmodified line
1169e.g.1170 \fB# Change the prompt to "loaded" when the input stream is complete1171 (seq 10; sleep 1; seq 11 20) | fzf --prompt 'Loading> ' --bind 'load:change-prompt:Loaded> '\fR1172.RE11731174\fIresize\fR1175.RS1176Triggered when the terminal size is changed.11771178e.g.1179 \fBfzf --bind 'resize:transform-header:echo Resized: ${FZF_COLUMNS}x${FZF_LINES}'\fR1180.RE11811182\fIresult\fR1183.RS1184Triggered when the filtering for the current query is complete and the result list is ready.1185
25 unmodified lines
12111212 # Beware not to introduce an infinite loop1213 seq 10 | fzf --bind 'focus:up' --cycle\fR1214.RE12151216\fIone\fR1217.RS1218Triggered when there's only one match. \fBone:accept\fR binding is comparable1219to \fB--select-1\fR option, but the difference is that \fB--select-1\fR is only
3 unmodified lines
1223e.g.1224 \fB# Automatically select the only match1225 seq 10 | fzf --bind one:accept\fR1226.RE12271228\fIzero\fR1229.RS1230Triggered when there's no match. \fBzero:abort\fR binding is comparable to1231\fB--exit-0\fR option, but the difference is that \fB--exit-0\fR is only
13 unmodified lines
1245e.g.1246 \fBfzf --bind backward-eof:abort\fR1247.RE12481249\fIjump\fR1250.RS1251Triggered when successfully jumped to the target item in \fB--jump\fR mode.12521253e.g.1254 \fBfzf --bind space:jump,jump:accept\fR1255.RE12561257\fIjump-cancel\fR1258.RS1259Triggered when \fB--jump\fR mode is cancelled.12601261e.g.1262 \fBfzf --bind space:jump,jump:accept,jump-cancel:abort\fR1263.RE12641265.SS AVAILABLE ACTIONS:1266A key or an event can be bound to one or more of the following actions.12671268 \fBACTION: DEFAULT BINDINGS (NOTES):
277 unmodified lines
modified:src/tui/tui.go+2 added
106 unmodified lines
107 Focus108 One109 Zero110 Result111 Jump112 JumpCancel113114 AltBS115116 AltUp
707 unmodified lines
modified:src/options.go+4 added
696 unmodified lines
697 case "one":698 add(tui.One)699 case "zero":700 add(tui.Zero)701 case "jump":702 add(tui.Jump)703 case "jump-cancel":704 add(tui.JumpCancel)705 case "alt-enter", "alt-return":706 chords[tui.CtrlAltKey('m')] = key707 case "alt-space":708 chords[tui.AltKey(' ')] = key
1600 unmodified lines
modified:src/terminal.go+12 added-8 removed
4106 unmodified lines
4107 if t.jumping == jumpDisabled || len(actions) > 0 {4108 // Break out of jump mode if any action is submitted to the server4109 if t.jumping != jumpDisabled {4110 t.jumping = jumpDisabled4111 if acts, prs := t.keymap[tui.JumpCancel.AsEvent()]; prs && !doActions(acts) {4112 continue4113 }4114 req(reqList)4115 }4116 if len(actions) == 0 {4117 actions = t.keymap[event.Comparable()]
5 unmodified lines
4123 }4124 t.truncateQuery()4125 queryChanged = string(previousInput) != string(t.input)4126 changed = changed || queryChanged4124 if onChanges, prs := t.keymap[tui.Change.AsEvent()]; queryChanged && prs {4125 if !doActions(onChanges) {4126 continue4127 }4127 if onChanges, prs := t.keymap[tui.Change.AsEvent()]; queryChanged && prs && !doActions(onChanges) {4128 continue4129 }4129 if onEOFs, prs := t.keymap[tui.BackwardEOF.AsEvent()]; beof && prs {4130 if !doActions(onEOFs) {4131 continue4132 }4130 if onEOFs, prs := t.keymap[tui.BackwardEOF.AsEvent()]; beof && prs && !doActions(onEOFs) {4131 continue4132 }4133 } else {4134 jumpEvent := tui.JumpCancel4135 if event.Type == tui.Rune {4136 if idx := strings.IndexRune(t.jumpLabels, event.Char); idx >= 0 && idx < t.maxItems() && idx < t.merger.Length() {4137 jumpEvent = tui.Jump4138 t.cy = idx + t.offset4139 if t.jumping == jumpAcceptEnabled {4140 req(reqClose)4141 }4142 }4143 }4144 t.jumping = jumpDisabled4145 if acts, prs := t.keymap[jumpEvent.AsEvent()]; prs && !doActions(acts) {4146 continue4147 }4148 req(reqList)4149 }41504151 if queryChanged && t.canPreview() && len(t.previewOpts.command) > 0 {
133 unmodified lines
modified:test/test_go.rb+13 added
1466 unmodified lines
1467 tmux.send_keys '3'1468 assert_equal '3', readonce.chomp1469 end14701471 def test_jump_events1472 tmux.send_keys "seq 1000 | #{fzf("--multi --jump-labels 12345 --bind 'ctrl-j:jump,jump:preview(echo jumped to {}),jump-cancel:preview(echo jump cancelled at {})'")}", :Enter1473 tmux.until { |lines| assert_equal ' 1000/1000 (0)', lines[-2] }1474 tmux.send_keys 'C-j'1475 tmux.until { |lines| assert_includes lines[-7], '5 5' }1476 tmux.send_keys '3'1477 tmux.until { |lines| assert(lines.any? { _1.include?('jumped to 3') }) }1478 tmux.send_keys 'C-j'1479 tmux.until { |lines| assert_includes lines[-7], '5 5' }1480 tmux.send_keys 'C-c'1481 tmux.until { |lines| assert(lines.any? { _1.include?('jump cancelled at 3') }) }1482 end14831484 def test_pointer1485 tmux.send_keys "seq 10 | #{fzf("--pointer '>>'")}", :Enter1486 # Assert that specified pointer is displayed1487 tmux.until { |lines| assert_equal '>> 1', lines[-3] }
2257 unmodified lines