From f55c990e863e995809912bded64fde4431e1961a Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 2 Feb 2021 00:08:54 +0900 Subject: [PATCH] Add `close` action Close #2331 --- CHANGELOG.md | 5 +++++ man/man1/fzf-tmux.1 | 2 +- man/man1/fzf.1 | 3 ++- src/options.go | 2 ++ src/terminal.go | 7 +++++++ test/test_go.rb | 13 +++++++++++++ 6 files changed, 30 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69bab6a..f181c12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +0.25.1 +------ +- Added `close` action + - Close preview window if open, abort fzf otherwise + 0.25.0 ------ - Text attributes set in `--color` are not reset when fzf sees another diff --git a/man/man1/fzf-tmux.1 b/man/man1/fzf-tmux.1 index 4f0c159..21cd013 100644 --- a/man/man1/fzf-tmux.1 +++ b/man/man1/fzf-tmux.1 @@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. .. -.TH fzf-tmux 1 "Jan 2021" "fzf 0.25.0" "fzf-tmux - open fzf in tmux split pane" +.TH fzf-tmux 1 "Feb 2021" "fzf 0.25.1" "fzf-tmux - open fzf in tmux split pane" .SH NAME fzf-tmux - open fzf in tmux split pane diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index 2455882..d29ed54 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. .. -.TH fzf 1 "Jan 2021" "fzf 0.25.0" "fzf - a command-line fuzzy finder" +.TH fzf 1 "Feb 2021" "fzf 0.25.1" "fzf - a command-line fuzzy finder" .SH NAME fzf - a command-line fuzzy finder @@ -780,6 +780,7 @@ A key or an event can be bound to one or more of the following actions. \fBchange-prompt(...)\fR (change prompt to the given string) \fBclear-screen\fR \fIctrl-l\fR \fBclear-selection\fR (clear multi-selection) + \fBclose\fR (close preview window if open, abort fzf otherwise) \fBclear-query\fR (clear query string) \fBdelete-char\fR \fIdel\fR \fBdelete-char/eof\fR \fIctrl-d\fR (same as \fBdelete-char\fR except aborts fzf if query is empty) diff --git a/src/options.go b/src/options.go index cee11ff..a55dc34 100644 --- a/src/options.go +++ b/src/options.go @@ -883,6 +883,8 @@ func parseKeymap(keymap map[tui.Event][]action, str string) { appendAction(actSelectAll) case "deselect-all": appendAction(actDeselectAll) + case "close": + appendAction(actClose) case "toggle": appendAction(actToggle) case "down": diff --git a/src/terminal.go b/src/terminal.go index f5fb480..fa9adb8 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -221,6 +221,7 @@ const ( actClearScreen actClearQuery actClearSelection + actClose actDeleteChar actDeleteCharEOF actEndOfLine @@ -2334,6 +2335,12 @@ func (t *Terminal) Loop() { } req(reqList, reqInfo) } + case actClose: + if t.isPreviewEnabled() { + togglePreview(false) + } else { + req(reqQuit) + } case actToggle: if t.multi > 0 && t.merger.Length() > 0 && toggle() { req(reqList) diff --git a/test/test_go.rb b/test/test_go.rb index 8f80589..a6651c2 100755 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -1877,6 +1877,19 @@ class TestGoFZF < TestBase tmux.send_keys 'C-w' end end + + def test_close + tmux.send_keys "seq 100 | #{FZF} --preview 'echo foo' --bind ctrl-c:close", :Enter + tmux.until { |lines| assert_equal 100, lines.match_count } + tmux.until { |lines| assert_includes lines[1], 'foo' } + tmux.send_keys 'C-c' + tmux.until { |lines| refute_includes lines[1], 'foo' } + tmux.send_keys '10' + tmux.until { |lines| assert_equal 2, lines.match_count } + tmux.send_keys 'C-c' + tmux.send_keys 'C-l', 'closed' + tmux.until { |lines| assert_includes lines[0], 'closed' } + end end module TestShell