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
Provenance
- Commit
a474562- Tree
18cb90f- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
17bb7ad
5 files changed+52 added−8 removed
modified:man/man1/fzf.1+21 added
1158 unmodified lines1159 e.g.1160 \fB# Move cursor to the last item and select all items1161 seq 1000 | fzf --multi --sync --bind start:last+select-all\fR1162 .RE1163+1164 \fIload\fR1165 .RS1166 Triggered when the input stream is complete and the initial processing of the1167 list is complete.1 unmodified line1169 e.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 .RE1173+1174 \fIresize\fR1175 .RS1176 Triggered when the terminal size is changed.1177 1178 e.g.1179 \fBfzf --bind 'resize:transform-header:echo Resized: ${FZF_COLUMNS}x${FZF_LINES}'\fR1180 .RE1181+1182 \fIresult\fR1183 .RS1184 Triggered when the filtering for the current query is complete and the result list is ready.1185 25 unmodified lines1211 1212 # Beware not to introduce an infinite loop1213 seq 10 | fzf --bind 'focus:up' --cycle\fR1214 .RE1215+1216 \fIone\fR1217 .RS1218 Triggered when there's only one match. \fBone:accept\fR binding is comparable1219 to \fB--select-1\fR option, but the difference is that \fB--select-1\fR is only3 unmodified lines1223 e.g.1224 \fB# Automatically select the only match1225 seq 10 | fzf --bind one:accept\fR1226 .RE1227+1228 \fIzero\fR1229 .RS1230 Triggered 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 only13 unmodified lines1245 e.g.1246 \fBfzf --bind backward-eof:abort\fR1247 .RE1248 1249+\fIjump\fR1250+.RS1251+Triggered when successfully jumped to the target item in \fB--jump\fR mode.1252+1253+e.g.1254+ \fBfzf --bind space:jump,jump:accept\fR1255+.RE1256+1257+\fIjump-cancel\fR1258+.RS1259+Triggered when \fB--jump\fR mode is cancelled.1260+1261+e.g.1262+ \fBfzf --bind space:jump,jump:accept,jump-cancel:abort\fR1263+.RE1264+1265 .SS AVAILABLE ACTIONS:1266 A key or an event can be bound to one or more of the following actions.1267 1268 \fBACTION: DEFAULT BINDINGS (NOTES):277 unmodified linesmodified:src/tui/tui.go+2 added
106 unmodified lines107 Focus108 One109 Zero110 Result111+ Jump112+ JumpCancel113 114 AltBS115 116 AltUp707 unmodified linesmodified:src/options.go+4 added
696 unmodified lines697 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(' ')] = key1600 unmodified linesmodified:src/terminal.go+12 added-8 removed
4106 unmodified lines4107 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 lines4123 }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 }4150 4151 if queryChanged && t.canPreview() && len(t.previewOpts.command) > 0 {133 unmodified linesmodified:test/test_go.rb+13 added
1466 unmodified lines1467 tmux.send_keys '3'1468 assert_equal '3', readonce.chomp1469 end1470 1471+ 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+ end1483+1484 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