Skip to content
Myr

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

5 files+35 added−0 removed

modified:man/man1/fzf.1+6 added
465 unmodified lines
466 \fIshift-right\fR467 \fIdouble-click\fR468 or any single character469470Additionally, a special event named \fIchange\fR is available which is471triggered whenever the query string is changed.472473 e.g. \fBfzf --bind change:top\fR474475 \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\fR
38 unmodified lines
517 \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\fR
62 unmodified lines
modified:src/tui/tui.go+2 added
73 unmodified lines
74 F1075 F1176 F127778 Change7980 AltSpace81 AltSlash82 AltBS83
345 unmodified lines
modified:src/options.go+4 added
398 unmodified lines
399 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.AltSpace
306 unmodified lines
715 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 lines
modified:src/terminal.go+9 added
211 unmodified lines
212 actExecute213 actExecuteSilent214 actExecuteMulti // Deprecated215 actSigStop216 actTop217)218219func toActions(types ...actionType) []action {220 actions := make([]action, len(types))
1388 unmodified lines
1609 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 lines
1752 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.offset
66 unmodified lines
modified:test/test_go.rb+14 added
1302 unmodified lines
1303 tmux.until { |lines| lines[-1] == prompt }1304 tmux.send_keys :Enter1305 tmux.until { |lines| lines[-2] == prompt && lines[-1] == '1' }1306 end13071308 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 end1321end13221323module TestShell1324 def setup
348 unmodified lines