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

@ -639,6 +639,7 @@ A key or an event can be bound to one or more of the following actions.
\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-delete-char\fR \fIctrl-h bspace\fR
\fBbackward-delete-char/eof\fR (same as \fBbackward-delete-char\fR except aborts fzf if query is empty)
\fBbackward-kill-word\fR \fIalt-bs\fR
\fBbackward-word\fR \fIalt-b shift-left\fR
\fBbeginning-of-line\fR \fIctrl-a home\fR
@ -647,7 +648,7 @@ A key or an event can be bound to one or more of the following actions.
\fBclear-selection\fR (clear multi-selection)
\fBclear-query\fR (clear query string)
\fBdelete-char\fR \fIdel\fR
\fBdelete-char/eof\fR \fIctrl-d\fR
\fBdelete-char/eof\fR \fIctrl-d\fR (same as \fBdelete-char\fR except aborts fzf if query is empty)
\fBdeselect-all\fR (deselect all matches)
\fBdown\fR \fIctrl-j ctrl-n down\fR
\fBend-of-line\fR \fIctrl-e end\fR

View File

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

View File

@ -187,6 +187,7 @@ const (
actAcceptNonEmpty
actBackwardChar
actBackwardDeleteChar
actBackwardDeleteCharEOF
actBackwardWord
actCancel
actClearScreen
@ -1846,6 +1847,13 @@ func (t *Terminal) Loop() {
t.input = []rune{}
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:
if t.cx < len(t.input) {
t.cx++

View File

@ -1710,6 +1710,20 @@ class TestGoFZF < TestBase
tmux.until { |lines| lines.match_count.zero? }
tmux.until { |lines| !lines[-2].include?('(1)') }
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
module TestShell