Skip to content
Myr

Preserve wrap state across change-preview-window

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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

authored by Junegunn Choi · committed by Junegunn Choi · parent 6fefe02 · Browse files · 3 files+53 added−0 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+53 added−0 removed

  • tests:+43 added−0 removed
  • other:+10 added−0 removed

3 files+53 added−0 removed

modified:src/terminal.go+5 added
7817 unmodified lines
7818 // Reset preview options and apply the additional options7819 t.previewOpts = t.initialPreviewOpts7820 t.previewOpts.command = currentPreviewOpts.command78217822 // Carry over toggle-driven state so toggle-preview-wrap survives7823 // a change-preview-window. Tokens below can still override.7824 t.previewOpts.wrap = currentPreviewOpts.wrap7825 t.previewOpts.wrapWord = currentPreviewOpts.wrapWord78267827 // Split window options7828 tokens := strings.Split(a.a, "|")7829 if len(tokens[0]) > 0 && t.initialPreviewOpts.hidden {7830 t.previewOpts.hidden = false
379 unmodified lines
modified:test/test_preview.rb+43 added
381 unmodified lines
382 tmux.send_keys 'C-w'383 end384 end385386 def test_change_preview_window_preserves_wrap_toggle387 # https://github.com/junegunn/fzf/issues/4791388 tmux.send_keys "#{FZF} --preview 'for i in $(seq $FZF_PREVIEW_COLUMNS); do echo -n .; done; echo -n .; echo wrapped; echo 2nd line' " \389 "--preview-window 'right,nowrap,border-rounded' " \390 '--bind ctrl-w:toggle-preview-wrap ' \391 '--bind ctrl-r:change-preview-window:border-bold', :Enter392 sleep 2393 # Initial: nowrap, rounded border. The long line is truncated; "wrapped" is hidden.394 tmux.until do |lines|395 assert_includes lines[2], '2nd line'396 assert(lines.any? { it.include?('╭') })397 end398 # Toggle wrap on.399 tmux.send_keys 'C-w'400 tmux.until do |lines|401 assert_includes lines[2], 'wrapped'402 assert_includes lines[3], '2nd line'403 end404 # change-preview-window swaps the border to bold; wrap state must persist.405 tmux.send_keys 'C-r'406 tmux.until do |lines|407 assert(lines.any? { it.include?('┏') }) # border actually changed408 refute(lines.any? { it.include?('╭') })409 assert_includes lines[2], 'wrapped' # wrap was preserved410 assert_includes lines[3], '2nd line'411 end412 end413414 def test_change_preview_window_overrides_wrap_explicitly415 # When the new spec sets wrap/nowrap explicitly, it should still win.416 tmux.send_keys "#{FZF} --preview 'for i in $(seq $FZF_PREVIEW_COLUMNS); do echo -n .; done; echo -n .; echo wrapped; echo 2nd line' " \417 "--preview-window 'right,wrap' " \418 '--bind ctrl-r:change-preview-window:nowrap', :Enter419 # Initial: wrap is on.420 tmux.until do |lines|421 assert_includes lines[2], 'wrapped'422 assert_includes lines[3], '2nd line'423 end424 # Explicit nowrap in the spec must override the (initially wrapped) state.425 tmux.send_keys 'C-r'426 tmux.until { |lines| assert_includes lines[2], '2nd line' }427 end428429 def test_preview_follow_wrap430 tmux.send_keys "seq 1 | #{FZF} --preview 'seq 1000' --preview-window right,2,follow,wrap", :Enter431 tmux.until { |lines| assert_equal 1, lines.match_count }432 tmux.until do |lines|
253 unmodified lines
modified:CHANGELOG.md+5 added
1CHANGELOG2=========340.73.05------6- Bug fixes7 - `change-preview-window` no longer resets `wrap` / `wrap-word` state set via `toggle-preview-wrap` / `toggle-preview-wrap-word`. Layout fields still snap to the preset, so cycling and the empty-token reset behave as before. The new spec can still override by including `wrap` or `nowrap` explicitly. (#4791)890.72.010------11_Release highlights: https://junegunn.github.io/fzf/releases/0.72.0/_12
3279 unmodified lines