Add toggle-in and toggle-out for --bind

Related: #452

When `--multi` is set, tab key will bring your cursor down, and
shift-tab up. But since fzf by default draws the screen in bottom-up
fashion, one may feel that the opposite of the behavior is more
desirable and choose to customize the key bindings as follows.

    export FZF_DEFAULT_OPTS="--bind tab:toggle-up,shift-tab:toggle-down"

This configuration, however, becomes no longer straightforward when
`--reverse` is set and fzf switches to top-down layout. To address the
requirement, this commit adds `toggle-in` and `toggle-out` option which
switch direction depending on `--reverse`-ness.

    export FZF_DEFAULT_OPTS="--bind tab:toggle-out,shift-tab:toggle-in"
This commit is contained in:
Junegunn Choi 2016-01-14 02:35:43 +09:00
parent 45143f9541
commit f6c6e59a50
3 changed files with 19 additions and 1 deletions

View File

@ -219,7 +219,7 @@ e.g. \fBfzf --bind=ctrl-j:accept,ctrl-k:kill-line\fR
.RE .RE
.RS .RS
\fBACTION: DEFAULT BINDINGS: \fBACTION: DEFAULT BINDINGS (NOTES):
\fBabort\fR \fIctrl-c ctrl-g ctrl-q esc\fR \fBabort\fR \fIctrl-c ctrl-g ctrl-q esc\fR
\fBaccept\fR \fIenter double-click\fR \fBaccept\fR \fIenter double-click\fR
\fBbackward-char\fR \fIctrl-b left\fR \fBbackward-char\fR \fIctrl-b left\fR
@ -249,6 +249,8 @@ e.g. \fBfzf --bind=ctrl-j:accept,ctrl-k:kill-line\fR
\fBtoggle\fR \fBtoggle\fR
\fBtoggle-all\fR \fBtoggle-all\fR
\fBtoggle-down\fR \fIctrl-i (tab)\fR \fBtoggle-down\fR \fIctrl-i (tab)\fR
\fBtoggle-in\fR (\fB--reverse\fR ? \fBtoggle-up\fR : \fBtoggle-down\fR)
\fBtoggle-out\fR (\fB--reverse\fR ? \fBtoggle-down\fR : \fBtoggle-up\fR)
\fBtoggle-sort\fR (equivalent to \fB--toggle-sort\fR) \fBtoggle-sort\fR (equivalent to \fB--toggle-sort\fR)
\fBtoggle-up\fR \fIbtab (shift-tab)\fR \fBtoggle-up\fR \fIbtab (shift-tab)\fR
\fBunix-line-discard\fR \fIctrl-u\fR \fBunix-line-discard\fR \fIctrl-u\fR

View File

@ -566,6 +566,10 @@ func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort b
keymap[key] = actToggleDown keymap[key] = actToggleDown
case "toggle-up": case "toggle-up":
keymap[key] = actToggleUp keymap[key] = actToggleUp
case "toggle-in":
keymap[key] = actToggleIn
case "toggle-out":
keymap[key] = actToggleOut
case "toggle-all": case "toggle-all":
keymap[key] = actToggleAll keymap[key] = actToggleAll
case "select-all": case "select-all":

View File

@ -125,6 +125,8 @@ const (
actToggleAll actToggleAll
actToggleDown actToggleDown
actToggleUp actToggleUp
actToggleIn
actToggleOut
actDown actDown
actUp actUp
actPageUp actPageUp
@ -949,6 +951,16 @@ func (t *Terminal) Loop() {
} }
req(reqList, reqInfo) req(reqList, reqInfo)
} }
case actToggleIn:
if t.reverse {
return doAction(actToggleUp, mapkey)
}
return doAction(actToggleDown, mapkey)
case actToggleOut:
if t.reverse {
return doAction(actToggleDown, mapkey)
}
return doAction(actToggleUp, mapkey)
case actToggleDown: case actToggleDown:
if t.multi && t.merger.Length() > 0 { if t.multi && t.merger.Length() > 0 {
toggle() toggle()