summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2021-02-02 00:08:54 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2021-02-02 00:11:05 +0900
commitf55c990e863e995809912bded64fde4431e1961a (patch)
tree71bfaa58e30168b376091f991ddb68c2e42f782d
parentd110372f99fe4cc905f7dea19f8f2eb4ee593c7b (diff)
Add `close` action
Close #2331
-rw-r--r--CHANGELOG.md5
-rw-r--r--man/man1/fzf-tmux.12
-rw-r--r--man/man1/fzf.13
-rw-r--r--src/options.go2
-rw-r--r--src/terminal.go7
-rwxr-xr-xtest/test_go.rb13
6 files changed, 30 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 69bab6a0..f181c124 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 4f0c1593..21cd0135 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 24558827..d29ed548 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 cee11ffc..a55dc340 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 f5fb4803..fa9adb88 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 8f805895..a6651c22 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