Implement bindable "change" event and "top" action
Before adoption: this commit came in with the history the project adopted, so no landing records it.
# Move cursor to the top result whenever the query string is changed fzf --bind change:top Close #925
authored by Junegunn Choi · committed by Junegunn Choi · parent 3a50867 · Browse files · 5 files·+35 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
5 files+35 added−0 removed
- tests:+14 added−0 removed
- other:+21 added−0 removed
Provenance
- Commit
e1e3339- Tree
33295b0- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
3a50867
5 files changed+35 added−0 removed
modified:man/man1/fzf.1+6 added
465 unmodified lines466 \fIshift-right\fR467 \fIdouble-click\fR468 or any single character469 470+Additionally, a special event named \fIchange\fR is available which is471+triggered whenever the query string is changed.472+473+ e.g. \fBfzf --bind change:top\fR474+475 \fBACTION: DEFAULT BINDINGS (NOTES):476 \fBabort\fR \fIctrl-c ctrl-g ctrl-q esc\fR477 \fBaccept\fR \fIenter double-click\fR478 \fBbackward-char\fR \fIctrl-b left\fR38 unmodified lines517 \fBtoggle-preview\fR518 \fBtoggle-preview-wrap\fR519 \fBtoggle-sort\fR520 \fBtoggle+up\fR \fIbtab (shift-tab)\fR521+ \fBtop\fR (move to the top result)522 \fBunix-line-discard\fR \fIctrl-u\fR523 \fBunix-word-rubout\fR \fIctrl-w\fR524 \fBup\fR \fIctrl-k ctrl-p up\fR525 \fByank\fR \fIctrl-y\fR62 unmodified linesmodified:src/tui/tui.go+2 added
73 unmodified lines74 F1075 F1176 F1277 78+ Change79+80 AltSpace81 AltSlash82 AltBS83 345 unmodified linesmodified:src/options.go+4 added
398 unmodified lines399 case "bspace", "bs":400 chord = tui.BSpace401 case "ctrl-space":402 chord = tui.CtrlSpace403+ case "change":404+ chord = tui.Change405 case "alt-enter", "alt-return":406 chord = tui.CtrlAltM407 case "alt-space":408 chord = tui.AltSpace306 unmodified lines715 case "down":716 appendAction(actDown)717 case "up":718 appendAction(actUp)719+ case "top":720+ appendAction(actTop)721 case "page-up":722 appendAction(actPageUp)723 case "page-down":724 appendAction(actPageDown)525 unmodified linesmodified:src/terminal.go+9 added
211 unmodified lines212 actExecute213 actExecuteSilent214 actExecuteMulti // Deprecated215 actSigStop216+ actTop217 )218 219 func toActions(types ...actionType) []action {220 actions := make([]action, len(types))1388 unmodified lines1609 case actAccept:1610 req(reqClose)1611 case actClearScreen:1612 req(reqRedraw)1613+ case actTop:1614+ t.vset(0)1615+ req(reqList)1616 case actUnixLineDiscard:1617 if t.cx > 0 {1618 t.yanked = copySlice(t.input[:t.cx])1619 t.input = t.input[t.cx:]132 unmodified lines1752 continue1753 }1754 t.truncateQuery()1755 changed = string(previousInput) != string(t.input)1756+ if onChanges, prs := t.keymap[tui.Change]; changed && prs {1757+ if !doActions(onChanges, tui.Change) {1758+ continue1759+ }1760+ }1761 } else {1762 if mapkey == tui.Rune {1763 if idx := strings.IndexRune(t.jumpLabels, event.Char); idx >= 0 && idx < t.maxItems() && idx < t.merger.Length() {1764 t.cy = idx + t.offset66 unmodified linesmodified:test/test_go.rb+14 added
1302 unmodified lines1303 tmux.until { |lines| lines[-1] == prompt }1304 tmux.send_keys :Enter1305 tmux.until { |lines| lines[-2] == prompt && lines[-1] == '1' }1306 end1307+1308+ def test_change_top1309+ tmux.send_keys %[seq 1000 | #{FZF} --bind change:top], :Enter1310+ tmux.until { |lines| lines.match_count == 1000 }1311+ tmux.send_keys :Up1312+ tmux.until { |lines| lines[-4] == '> 2' }1313+ tmux.send_keys 11314+ tmux.until { |lines| lines[-3] == '> 1' }1315+ tmux.send_keys :Up1316+ tmux.until { |lines| lines[-4] == '> 10' }1317+ tmux.send_keys 11318+ tmux.until { |lines| lines[-3] == '> 11' }1319+ tmux.send_keys :Enter1320+ end1321 end1322 1323 module TestShell1324 def setup348 unmodified lines