summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2023-01-30 22:05:34 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2023-01-30 22:13:29 +0900
commit3ee00f8bc281e98e06689c127ebd09c0ed123929 (patch)
treed30a858566fa3951ba2f4f93cd45a4317d44cb50
parentfccab60a5cd0b6e74cb8fd5a7d87f4baaeba2f95 (diff)
toggle-preview should not show empty preview window
-rw-r--r--src/terminal.go2
-rwxr-xr-xtest/test_go.rb38
2 files changed, 39 insertions, 1 deletions
diff --git a/src/terminal.go b/src/terminal.go
index 8c6259a4..8308f63d 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -2867,7 +2867,7 @@ func (t *Terminal) Loop() {
t.mutex.Unlock()
return false
case actTogglePreview:
- if t.hasPreviewer() {
+ if t.hasPreviewWindow() || len(t.previewOpts.command) > 0 {
t.activePreviewOpts.Toggle()
updatePreviewWindow(false)
if t.isPreviewEnabled() {
diff --git a/test/test_go.rb b/test/test_go.rb
index fc8e149d..9d95a0a1 100755
--- a/test/test_go.rb
+++ b/test/test_go.rb
@@ -1457,6 +1457,44 @@ class TestGoFZF < TestBase
tmux.until { |lines| assert_includes lines[1], ' {5-1 3 4} ' }
end
+ def test_toggle_preview_without_default_preview_command
+ tmux.send_keys %(seq 100 | #{FZF} --bind 'space:preview(echo [{}]),enter:toggle-preview' --preview-window up,border-double), :Enter
+ tmux.until do |lines|
+ assert_equal 100, lines.match_count
+ refute_includes lines[1], '║ [1]'
+ end
+
+ # toggle-preview should do nothing
+ tmux.send_keys :Enter
+ tmux.until { |lines| refute_includes lines[1], '║ [1]' }
+ tmux.send_keys :Up
+ tmux.until do |lines|
+ refute_includes lines[1], '║ [1]'
+ refute_includes lines[1], '║ [2]'
+ end
+
+ tmux.send_keys :Up
+ tmux.until do |lines|
+ assert_includes lines, '> 3'
+ refute_includes lines[1], '║ [3]'
+ end
+
+ # One-off preview action
+ tmux.send_keys :Space
+ tmux.until { |lines| assert_includes lines[1], '║ [3]' }
+
+ # toggle-preview to hide it
+ tmux.send_keys :Enter
+ tmux.until { |lines| refute_includes lines[1], '║ [3]' }
+
+ # toggle-preview again does nothing
+ tmux.send_keys :Enter, :Up
+ tmux.until do |lines|
+ assert_includes lines, '> 4'
+ refute_includes lines[1], '║ [4]'
+ end
+ end
+
def test_preview_hidden
tmux.send_keys %(seq 1000 | #{FZF} --preview 'echo {{}-{}-$FZF_PREVIEW_LINES-$FZF_PREVIEW_COLUMNS}' --preview-window down:1:hidden --bind ?:toggle-preview), :Enter
tmux.until { |lines| assert_equal '>', lines[-1] }