`--preview-window 0,hidden` should not execute the preview command
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Until `toggle-preview` action is triggered Fix #3149
authored by Junegunn Choi · committed by Junegunn Choi · parent 0f4af38 · Browse files · 3 files·+51 added−69 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+51 added−69 removed
- tests:+41 added−63 removed
- other:+10 added−6 removed
Provenance
- Commit
fccab60- Tree
ba2e6e0- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
0f4af38
3 files changed+51 added−69 removed
modified:src/terminal.go+4 added-6 removed
1242 unmodified lines1243 }1244 }1245 }1246 resizePreviewWindows(&t.previewOpts)1247+ } else {1248+ t.activePreviewOpts = &t.previewOpts1249 }1250 1251 // Without preview window1252 if t.window == nil {1027 unmodified lines2280 }2281 2282 // Check if previewer is currently in action (invisible previewer with size 0 or visible previewer)2283 func (t *Terminal) isPreviewEnabled() bool {2282- return t.hasPreviewer() && t.previewer.enabled && (!t.previewOpts.Visible() || t.pwindow != nil)2284+ return t.hasPreviewer() && t.previewer.enabled && (!t.previewOpts.Visible() && !t.previewOpts.hidden || t.pwindow != nil)2285 }2286 2287 func (t *Terminal) hasPreviewWindow() bool {2288 return t.pwindow != nil578 unmodified lines2867 t.mutex.Unlock()2868 return false2869 case actTogglePreview:2870 if t.hasPreviewer() {2869- if t.activePreviewOpts != nil {2870- t.activePreviewOpts.Toggle()2871+ t.activePreviewOpts.Toggle()2871- } else if !t.previewOpts.Visible() {2872- t.previewer.enabled = !t.previewer.enabled2873- }2872 updatePreviewWindow(false)2873 if t.isPreviewEnabled() {2874 valid, list := t.buildPlusList(t.previewOpts.command, false, false)2875 if valid {691 unmodified linesmodified:test/test_go.rb+41 added-63 removed
178 unmodified lines179 @temp_suffix].join('-')180 end181 182 def writelines(path, lines)183- File.unlink(path) while File.exist?(path)183+ FileUtils.rm_f(path) while File.exist?(path)184 File.open(path, 'w') { |f| f.puts lines }185 end186 187 def readonce188 wait { assert_path_exists tempname }189 File.read(tempname)190 ensure191- File.unlink(tempname) while File.exist?(tempname)191+ FileUtils.rm_f(tempname) while File.exist?(tempname)192 @temp_suffix += 1193 tmux.prepare194 end195 708 unmodified lines904 def test_history905 history_file = '/tmp/fzf-test-history'906 907 # History with limited number of entries908- begin909- File.unlink(history_file)908+ FileUtils.rm_f(history_file)910- rescue StandardError911- nil912- end909 opts = "--history=#{history_file} --history-size=4"910 input = %w[00 11 22 33 44]911 input.each do |keys|912 tmux.prepare37 unmodified lines950 tmux.send_keys 'C-n', 'C-n', 'C-n', 'C-n', 'C-p'951 tmux.until { |lines| assert_equal '> 33', lines[-1] }952 tmux.send_keys :Enter953 ensure958- File.unlink(history_file)954+ FileUtils.rm_f(history_file)955 end956 957 def test_execute958 output = '/tmp/fzf-test-execute'20 unmodified lines979 /foo$barfoo$barfoo$bar/980 ], File.readlines(output, chomp: true)981 end982 ensure987- begin988- File.unlink(output)983+ FileUtils.rm_f(output)989- rescue StandardError990- nil991- end984 end985 986 def test_execute_multi987 output = '/tmp/fzf-test-execute-multi'16 unmodified lines1004 %(foo'bar foo"bar foobar/foo'bar foo"bar foobar)1005 ], File.readlines(output, chomp: true)1006 end1007 ensure1016- begin1017- File.unlink(output)1008+ FileUtils.rm_f(output)1018- rescue StandardError1019- nil1020- end1009 end1010 1011 def test_execute_plus_flag1012 output = tempname + '.tmp'1025- begin1026- File.unlink(output)1013+ FileUtils.rm_f(output)1027- rescue StandardError1028- nil1029- end1014 writelines(tempname, ['foo bar', '123 456'])1015 1016 tmux.send_keys "cat #{tempname} | #{FZF} --multi --bind 'x:execute-silent(echo {+}/{}/{+2}/{2} >> #{output})'", :Enter1017 24 unmodified lines1042 %(123 456 foo bar/foo bar/456 bar/bar)1043 ], File.readlines(output, chomp: true)1044 end1045 rescue StandardError1062- begin1063- File.unlink(output)1046+ FileUtils.rm_f(output)1064- rescue StandardError1065- nil1066- end1047 end1048 1049 def test_execute_shell1050 # Custom script to use as $SHELL1051 output = tempname + '.out'1072- begin1073- File.unlink(output)1052+ FileUtils.rm_f(output)1074- rescue StandardError1075- nil1076- end1053 writelines(tempname,1054 ['#!/usr/bin/env bash', "echo $1 / $2 > #{output}"])1055 system("chmod +x #{tempname}")1056 5 unmodified lines1062 assert_path_exists output1063 assert_equal ["-c / 'foo'bar"], File.readlines(output, chomp: true)1064 end1065 ensure1090- begin1091- File.unlink(output)1066+ FileUtils.rm_f(output)1092- rescue StandardError1093- nil1094- end1067 end1068 1069 def test_cycle1070 tmux.send_keys "seq 8 | #{fzf(:cycle)}", :Enter397 unmodified lines1468 tmux.until { |lines| assert_equal '> 555', lines[-1] }1469 end1470 1471 def test_preview_size_01500- begin1501- File.unlink(tempname)1472+ FileUtils.rm_f(tempname)1502- rescue StandardError1503- nil1504- end1473 tmux.send_keys %(seq 100 | #{FZF} --reverse --preview 'echo {} >> #{tempname}; echo ' --preview-window 0 --bind space:toggle-preview), :Enter1474 tmux.until do |lines|1475 assert_equal 100, lines.item_count1476 assert_equal ' 100/100', lines[1]16 unmodified lines1493 assert_equal %w[1 3 4], File.readlines(tempname, chomp: true)1494 end1495 end1496 1497+ def test_preview_size_0_hidden1498+ FileUtils.rm_f(tempname)1499+ tmux.send_keys %(seq 100 | #{FZF} --reverse --preview 'echo {} >> #{tempname}; echo ' --preview-window 0,hidden --bind space:toggle-preview), :Enter1500+ tmux.until { |lines| assert_equal 100, lines.item_count }1501+ tmux.send_keys :Down, :Down1502+ tmux.until { |lines| assert_includes lines, '> 3' }1503+ wait { refute_path_exists tempname }1504+ tmux.send_keys :Space1505+ wait do1506+ assert_path_exists tempname1507+ assert_equal %w[3], File.readlines(tempname, chomp: true)1508+ end1509+ tmux.send_keys :Down1510+ wait do1511+ assert_equal %w[3 4], File.readlines(tempname, chomp: true)1512+ end1513+ tmux.send_keys :Space, :Down1514+ tmux.until { |lines| assert_includes lines, '> 5' }1515+ tmux.send_keys :Down1516+ tmux.until { |lines| assert_includes lines, '> 6' }1517+ tmux.send_keys :Space1518+ wait do1519+ assert_equal %w[3 4 6], File.readlines(tempname, chomp: true)1520+ end1521+ end1522+1523 def test_preview_flags1524 tmux.send_keys %(seq 10 | sed 's/^/:: /; s/$/ /' |1525 #{FZF} --multi --preview 'echo {{2}/{s2}/{+2}/{+s2}/{q}/{n}/{+n}}'), :Enter1526 tmux.until { |lines| assert_includes lines[1], ' {1/1 /1/1 //0/0} ' }553 unmodified lines2080 tmux.until { |lines| assert_includes lines[0], 'closed' }2081 wait { refute system("pgrep -f #{script}") }2082 ensure2083 system("pkill -9 -f #{script}")2090- begin2091- File.unlink(script)2084+ FileUtils.rm_f(script)2092- rescue StandardError2093- nil2094- end2085 end2086 2087 def test_kill_default_command_on_accept2088 script = tempname + '.sh'9 unmodified lines2098 assert_equal 'Started', readonce.chomp2099 wait { refute system("pgrep -f #{script}") }2100 ensure2101 system("pkill -9 -f #{script}")2112- begin2113- File.unlink(script)2102+ FileUtils.rm_f(script)2114- rescue StandardError2115- nil2116- end2103 end2104 2105 def test_kill_reload_command_on_abort2106 script = tempname + '.sh'12 unmodified lines2119 tmux.until { |lines| assert_includes lines[0], 'closed' }2120 wait { refute system("pgrep -f #{script}") }2121 ensure2122 system("pkill -9 -f #{script}")2137- begin2138- File.unlink(script)2123+ FileUtils.rm_f(script)2139- rescue StandardError2140- nil2141- end2124 end2125 2126 def test_kill_reload_command_on_accept2127 script = tempname + '.sh'11 unmodified lines2139 assert_equal 'Started', readonce.chomp2140 wait { refute system("pgrep -f #{script}") }2141 ensure2142 system("pkill -9 -f #{script}")2161- begin2162- File.unlink(script)2143+ FileUtils.rm_f(script)2163- rescue StandardError2164- nil2165- end2144 end2145 2146 def test_preview_header2147 tmux.send_keys "seq 100 | #{FZF} --bind ctrl-k:preview-up+preview-up,ctrl-j:preview-down+preview-down+preview-down --preview 'seq 1000' --preview-window 'top:+{1}:~3'", :Enter906 unmodified linesmodified:CHANGELOG.md+6 added
1 CHANGELOG2 =========3 4+0.37.15+------6+- Bug fixes7+ - `--preview-window 0,hidden` should not execute the preview command until8+ `toggle-preview` action is triggered9+10 0.37.011 ------12 - Added a way to customize the separator of inline info13 ```sh1535 unmodified lines