Preserve wrap state across change-preview-window
CodeQL / Analyze (go) (push) Has been cancelled
build / build (push) Has been cancelled
Test fzf on macOS / build (push) Has been cancelled

toggle-preview-wrap (and -wrap-word) modifies t.activePreviewOpts.wrap,
but change-preview-window resets t.previewOpts to t.initialPreviewOpts,
discarding the user's toggle. Carry wrap and wrapWord over so toggles
survive a layout change. Explicit wrap / nowrap tokens in the new spec
still win, so cycling and the empty-token reset are unaffected.

Close #4791
This commit is contained in:
Junegunn Choi
2026-05-02 15:40:41 +09:00
parent 6fefe02546
commit b4a86a9c8a
3 changed files with 53 additions and 0 deletions
+43
View File
@@ -383,6 +383,49 @@ class TestPreview < TestInteractive
end
end
def test_change_preview_window_preserves_wrap_toggle
# https://github.com/junegunn/fzf/issues/4791
tmux.send_keys "#{FZF} --preview 'for i in $(seq $FZF_PREVIEW_COLUMNS); do echo -n .; done; echo -n .; echo wrapped; echo 2nd line' " \
"--preview-window 'right,nowrap,border-rounded' " \
'--bind ctrl-w:toggle-preview-wrap ' \
'--bind ctrl-r:change-preview-window:border-bold', :Enter
sleep 2
# Initial: nowrap, rounded border. The long line is truncated; "wrapped" is hidden.
tmux.until do |lines|
assert_includes lines[2], '2nd line'
assert(lines.any? { it.include?('╭') })
end
# Toggle wrap on.
tmux.send_keys 'C-w'
tmux.until do |lines|
assert_includes lines[2], 'wrapped'
assert_includes lines[3], '2nd line'
end
# change-preview-window swaps the border to bold; wrap state must persist.
tmux.send_keys 'C-r'
tmux.until do |lines|
assert(lines.any? { it.include?('┏') }) # border actually changed
refute(lines.any? { it.include?('╭') })
assert_includes lines[2], 'wrapped' # wrap was preserved
assert_includes lines[3], '2nd line'
end
end
def test_change_preview_window_overrides_wrap_explicitly
# When the new spec sets wrap/nowrap explicitly, it should still win.
tmux.send_keys "#{FZF} --preview 'for i in $(seq $FZF_PREVIEW_COLUMNS); do echo -n .; done; echo -n .; echo wrapped; echo 2nd line' " \
"--preview-window 'right,wrap' " \
'--bind ctrl-r:change-preview-window:nowrap', :Enter
# Initial: wrap is on.
tmux.until do |lines|
assert_includes lines[2], 'wrapped'
assert_includes lines[3], '2nd line'
end
# Explicit nowrap in the spec must override the (initially wrapped) state.
tmux.send_keys 'C-r'
tmux.until { |lines| assert_includes lines[2], '2nd line' }
end
def test_preview_follow_wrap
tmux.send_keys "seq 1 | #{FZF} --preview 'seq 1000' --preview-window right,2,follow,wrap", :Enter
tmux.until { |lines| assert_equal 1, lines.match_count }