Skip to content

Commit

Permalink
Add clear-query and clear-selection
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed Dec 7, 2019
1 parent 86e3994 commit af1a5f1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions man/man1/fzf.1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
11 changes: 11 additions & 0 deletions src/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ const (
actBackwardWord
actCancel
actClearScreen
actClearQuery
actClearSelection
actDeleteChar
actDeleteCharEOF
actEndOfLine
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions test/test_go.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,29 @@ def test_clear_list_when_header_lines_changed_due_to_reload
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
Expand Down

0 comments on commit af1a5f1

Please sign in to comment.