summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2019-12-07 14:44:24 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2019-12-07 14:44:24 +0900
commitaf1a5f130bbd2464131ec2ae91c538ace6801a73 (patch)
tree29603019f0a61d0b212ec9220b4b54070f879c46
parent86e3994e87b264f874ea1620fc31f42e3744aad0 (diff)
Add clear-query and clear-selection
Close #1787 Related #1364
-rw-r--r--CHANGELOG.md1
-rw-r--r--man/man1/fzf.110
-rw-r--r--src/options.go4
-rw-r--r--src/terminal.go11
-rwxr-xr-xtest/test_go.rb23
5 files changed, 45 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3a1a47d4..7c0d3a67 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 877330cd..db7d2870 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 bb7333ca..bd88f23f 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 3cd0af6e..d31ff6fe 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 55c8fc2b..d2fe1809 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