diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a1a47d..7c0d3a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ CHANGELOG ```sh : | fzf --bind 'change:reload:seq {q}' --phony ``` +- Added `clear-query` and `clear-selection` actions for `--bind` - It is now possible to split a composite bind action over multiple `--bind` expressions by prefixing the later ones with `+`. ```sh diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index 877330c..db7d287 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -632,11 +632,13 @@ A key or an event can be bound to one or more of the following actions. \fBbackward-kill-word\fR \fIalt-bs\fR \fBbackward-word\fR \fIalt-b shift-left\fR \fBbeginning-of-line\fR \fIctrl-a home\fR - \fBcancel\fR (clears query string if not empty, aborts fzf otherwise) + \fBcancel\fR (clear query string if not empty, abort fzf otherwise) \fBclear-screen\fR \fIctrl-l\fR + \fBclear-selection\fR (clear multi-selection) + \fBclear-query\fR (clear query string) \fBdelete-char\fR \fIdel\fR \fBdelete-char/eof\fR \fIctrl-d\fR - \fBdeselect-all\fR + \fBdeselect-all\fR (deselect all matches) \fBdown\fR \fIctrl-j ctrl-n down\fR \fBend-of-line\fR \fIctrl-e end\fR \fBexecute(...)\fR (see below for the details) @@ -662,9 +664,9 @@ A key or an event can be bound to one or more of the following actions. \fBprint-query\fR (print query and exit) \fBreload(...)\fR (see below for the details) \fBreplace-query\fR (replace query string with the current selection) - \fBselect-all\fR + \fBselect-all\fR (select all matches) \fBtoggle\fR (\fIright-click\fR) - \fBtoggle-all\fR + \fBtoggle-all\fR (toggle all matches) \fBtoggle+down\fR \fIctrl-i (tab)\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) diff --git a/src/options.go b/src/options.go index bb7333c..bd88f23 100644 --- a/src/options.go +++ b/src/options.go @@ -738,6 +738,10 @@ func parseKeymap(keymap map[int][]action, str string) { appendAction(actEndOfLine) case "cancel": appendAction(actCancel) + case "clear-query": + appendAction(actClearQuery) + case "clear-selection": + appendAction(actClearSelection) case "forward-char": appendAction(actForwardChar) case "forward-word": diff --git a/src/terminal.go b/src/terminal.go index 3cd0af6..d31ff6f 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -185,6 +185,8 @@ const ( actBackwardWord actCancel actClearScreen + actClearQuery + actClearSelection actDeleteChar actDeleteCharEOF actEndOfLine @@ -1905,6 +1907,15 @@ func (t *Terminal) Loop() { } case actClearScreen: req(reqRedraw) + case actClearQuery: + t.input = []rune{} + t.cx = 0 + case actClearSelection: + if t.multi > 0 { + t.selected = make(map[int32]selectedItem) + t.version++ + req(reqList, reqInfo) + } case actTop: t.vset(0) req(reqList) diff --git a/test/test_go.rb b/test/test_go.rb index 55c8fc2..d2fe180 100755 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -1654,6 +1654,29 @@ class TestGoFZF < TestBase tmux.send_keys :Space tmux.until { |lines| lines.none? { |line| line.include?('9') } } end + + def test_clear_query + tmux.send_keys %(: | #{FZF} --query foo --bind space:clear-query), :Enter + tmux.until { |lines| lines.item_count.zero? } + tmux.until { |lines| lines.last.include?('> foo') } + tmux.send_keys 'C-a', 'bar' + tmux.until { |lines| lines.last.include?('> barfoo') } + tmux.send_keys :Space + tmux.until { |lines| lines.last == '>' } + end + + def test_clear_selection + tmux.send_keys %(seq 100 | #{FZF} --multi --bind space:clear-selection), :Enter + tmux.until { |lines| lines.match_count == 100 } + tmux.send_keys :Tab + tmux.until { |lines| lines[-2].include?('(1)') } + tmux.send_keys 'foo' + tmux.until { |lines| lines.match_count.zero? } + tmux.until { |lines| lines[-2].include?('(1)') } + tmux.send_keys :Space + tmux.until { |lines| lines.match_count.zero? } + tmux.until { |lines| !lines[-2].include?('(1)') } + end end module TestShell