Add backward-delete-char/eof action (#1891)

'backward-delete-char/eof' will either abort if query is
empty or delete one character backwards.
This commit is contained in:
James Wright 2020-02-27 10:38:32 -07:00 committed by GitHub
parent d8cb5c1cf5
commit 9f0626da64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 72 additions and 47 deletions

View File

@ -633,62 +633,63 @@ or any single character
.SS AVAILABLE ACTIONS: .SS AVAILABLE ACTIONS:
A key or an event can be bound to one or more of the following actions. A key or an event can be bound to one or more of the following actions.
\fBACTION: DEFAULT BINDINGS (NOTES): \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
\fBaccept-non-empty\fR (same as \fBaccept\fR except that it prevents fzf from exiting without selection) \fBaccept-non-empty\fR (same as \fBaccept\fR except that it prevents fzf from exiting without selection)
\fBbackward-char\fR \fIctrl-b left\fR \fBbackward-char\fR \fIctrl-b left\fR
\fBbackward-delete-char\fR \fIctrl-h bspace\fR \fBbackward-delete-char\fR \fIctrl-h bspace\fR
\fBbackward-kill-word\fR \fIalt-bs\fR \fBbackward-delete-char/eof\fR (same as \fBbackward-delete-char\fR except aborts fzf if query is empty)
\fBbackward-word\fR \fIalt-b shift-left\fR \fBbackward-kill-word\fR \fIalt-bs\fR
\fBbeginning-of-line\fR \fIctrl-a home\fR \fBbackward-word\fR \fIalt-b shift-left\fR
\fBcancel\fR (clear query string if not empty, abort fzf otherwise) \fBbeginning-of-line\fR \fIctrl-a home\fR
\fBclear-screen\fR \fIctrl-l\fR \fBcancel\fR (clear query string if not empty, abort fzf otherwise)
\fBclear-selection\fR (clear multi-selection) \fBclear-screen\fR \fIctrl-l\fR
\fBclear-query\fR (clear query string) \fBclear-selection\fR (clear multi-selection)
\fBdelete-char\fR \fIdel\fR \fBclear-query\fR (clear query string)
\fBdelete-char/eof\fR \fIctrl-d\fR \fBdelete-char\fR \fIdel\fR
\fBdeselect-all\fR (deselect all matches) \fBdelete-char/eof\fR \fIctrl-d\fR (same as \fBdelete-char\fR except aborts fzf if query is empty)
\fBdown\fR \fIctrl-j ctrl-n down\fR \fBdeselect-all\fR (deselect all matches)
\fBend-of-line\fR \fIctrl-e end\fR \fBdown\fR \fIctrl-j ctrl-n down\fR
\fBexecute(...)\fR (see below for the details) \fBend-of-line\fR \fIctrl-e end\fR
\fBexecute-silent(...)\fR (see below for the details) \fBexecute(...)\fR (see below for the details)
\fRexecute-multi(...)\fR (deprecated in favor of \fB{+}\fR expression) \fBexecute-silent(...)\fR (see below for the details)
\fBforward-char\fR \fIctrl-f right\fR \fRexecute-multi(...)\fR (deprecated in favor of \fB{+}\fR expression)
\fBforward-word\fR \fIalt-f shift-right\fR \fBforward-char\fR \fIctrl-f right\fR
\fBforward-word\fR \fIalt-f shift-right\fR
\fBignore\fR \fBignore\fR
\fBjump\fR (EasyMotion-like 2-keystroke movement) \fBjump\fR (EasyMotion-like 2-keystroke movement)
\fBjump-accept\fR (jump and accept) \fBjump-accept\fR (jump and accept)
\fBkill-line\fR \fBkill-line\fR
\fBkill-word\fR \fIalt-d\fR \fBkill-word\fR \fIalt-d\fR
\fBnext-history\fR (\fIctrl-n\fR on \fB--history\fR) \fBnext-history\fR (\fIctrl-n\fR on \fB--history\fR)
\fBpage-down\fR \fIpgdn\fR \fBpage-down\fR \fIpgdn\fR
\fBpage-up\fR \fIpgup\fR \fBpage-up\fR \fIpgup\fR
\fBhalf-page-down\fR \fBhalf-page-down\fR
\fBhalf-page-up\fR \fBhalf-page-up\fR
\fBpreview-down\fR \fIshift-down\fR \fBpreview-down\fR \fIshift-down\fR
\fBpreview-up\fR \fIshift-up\fR \fBpreview-up\fR \fIshift-up\fR
\fBpreview-page-down\fR \fBpreview-page-down\fR
\fBpreview-page-up\fR \fBpreview-page-up\fR
\fBprevious-history\fR (\fIctrl-p\fR on \fB--history\fR) \fBprevious-history\fR (\fIctrl-p\fR on \fB--history\fR)
\fBprint-query\fR (print query and exit) \fBprint-query\fR (print query and exit)
\fBreload(...)\fR (see below for the details) \fBreload(...)\fR (see below for the details)
\fBreplace-query\fR (replace query string with the current selection) \fBreplace-query\fR (replace query string with the current selection)
\fBselect-all\fR (select all matches) \fBselect-all\fR (select all matches)
\fBtoggle\fR (\fIright-click\fR) \fBtoggle\fR (\fIright-click\fR)
\fBtoggle-all\fR (toggle all matches) \fBtoggle-all\fR (toggle all matches)
\fBtoggle+down\fR \fIctrl-i (tab)\fR \fBtoggle+down\fR \fIctrl-i (tab)\fR
\fBtoggle-in\fR (\fB--layout=reverse*\fR ? \fBtoggle+up\fR : \fBtoggle+down\fR) \fBtoggle-in\fR (\fB--layout=reverse*\fR ? \fBtoggle+up\fR : \fBtoggle+down\fR)
\fBtoggle-out\fR (\fB--layout=reverse*\fR ? \fBtoggle+down\fR : \fBtoggle+up\fR) \fBtoggle-out\fR (\fB--layout=reverse*\fR ? \fBtoggle+down\fR : \fBtoggle+up\fR)
\fBtoggle-preview\fR \fBtoggle-preview\fR
\fBtoggle-preview-wrap\fR \fBtoggle-preview-wrap\fR
\fBtoggle-sort\fR \fBtoggle-sort\fR
\fBtoggle+up\fR \fIbtab (shift-tab)\fR \fBtoggle+up\fR \fIbtab (shift-tab)\fR
\fBtop\fR (move to the top result) \fBtop\fR (move to the top result)
\fBunix-line-discard\fR \fIctrl-u\fR \fBunix-line-discard\fR \fIctrl-u\fR
\fBunix-word-rubout\fR \fIctrl-w\fR \fBunix-word-rubout\fR \fIctrl-w\fR
\fBup\fR \fIctrl-k ctrl-p up\fR \fBup\fR \fIctrl-k ctrl-p up\fR
\fByank\fR \fIctrl-y\fR \fByank\fR \fIctrl-y\fR
.SS ACTION COMPOSITION .SS ACTION COMPOSITION

View File

@ -740,6 +740,8 @@ func parseKeymap(keymap map[int][]action, str string) {
appendAction(actBackwardChar) appendAction(actBackwardChar)
case "backward-delete-char": case "backward-delete-char":
appendAction(actBackwardDeleteChar) appendAction(actBackwardDeleteChar)
case "backward-delete-char/eof":
appendAction(actBackwardDeleteCharEOF)
case "backward-word": case "backward-word":
appendAction(actBackwardWord) appendAction(actBackwardWord)
case "clear-screen": case "clear-screen":

View File

@ -187,6 +187,7 @@ const (
actAcceptNonEmpty actAcceptNonEmpty
actBackwardChar actBackwardChar
actBackwardDeleteChar actBackwardDeleteChar
actBackwardDeleteCharEOF
actBackwardWord actBackwardWord
actCancel actCancel
actClearScreen actClearScreen
@ -1846,6 +1847,13 @@ func (t *Terminal) Loop() {
t.input = []rune{} t.input = []rune{}
t.cx = 0 t.cx = 0
} }
case actBackwardDeleteCharEOF:
if len(t.input) == 0 {
req(reqQuit)
} else if t.cx > 0 {
t.input = append(t.input[:t.cx-1], t.input[t.cx:]...)
t.cx--
}
case actForwardChar: case actForwardChar:
if t.cx < len(t.input) { if t.cx < len(t.input) {
t.cx++ t.cx++

View File

@ -1710,6 +1710,20 @@ class TestGoFZF < TestBase
tmux.until { |lines| lines.match_count.zero? } tmux.until { |lines| lines.match_count.zero? }
tmux.until { |lines| !lines[-2].include?('(1)') } tmux.until { |lines| !lines[-2].include?('(1)') }
end end
def test_backward_delete_char_eof
tmux.send_keys "seq 1000 | #{fzf "--bind 'bs:backward-delete-char/eof'"}", :Enter
tmux.until { |lines| lines[-2] == ' 1000/1000' }
tmux.send_keys '11'
tmux.until { |lines| lines[-1] == '> 11' }
tmux.send_keys :BSpace
tmux.until { |lines| lines[-1] == '> 1' }
tmux.send_keys :BSpace
tmux.until { |lines| lines[-1] == '>' }
tmux.send_keys :BSpace
tmux.prepare
end
end end
module TestShell module TestShell