From 0ecbf3f475d6a69f7c38e92727cf28531420d70a Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Thu, 19 Feb 2026 19:49:13 +0900 Subject: [PATCH] Fix missing wrap sign at ANSI color boundary --- src/terminal.go | 12 +++++++++++- test/test_preview.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/terminal.go b/src/terminal.go index efc4add6..25d60c32 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -4340,6 +4340,12 @@ Loop: var fillRet tui.FillReturn wrap := t.activePreviewOpts.wrap + printWrapSign := func() { + if t.pwindow.CFill(tui.ColPreview.Fg(), tui.ColPreview.Bg(), -1, tui.Dim, t.wrapSign) == tui.FillNextLine { + t.pwindow.Move(t.pwindow.Y()-1, t.pwindow.Width()) + } + fillRet = tui.FillContinue + } for subIdx, subLine := range subLines { // Render wrap sign for continuation sub-lines if subIdx > 0 { @@ -4350,12 +4356,16 @@ Loop: break Loop } } - t.pwindow.CFill(tui.ColPreview.Fg(), tui.ColPreview.Bg(), -1, tui.Dim, t.wrapSign) + printWrapSign() } prefixWidth := t.pwindow.X() var url *url _, _, ansi = extractColor(subLine, ansi, func(str string, ansi *ansiState) bool { + if fillRet == tui.FillNextLine { + printWrapSign() + prefixWidth = t.pwindow.X() + } trimmed := []rune(str) isTrimmed := false if !wrap { diff --git a/test/test_preview.rb b/test/test_preview.rb index b1953afe..0da1a88b 100644 --- a/test/test_preview.rb +++ b/test/test_preview.rb @@ -582,4 +582,31 @@ class TestPreview < TestInteractive assert_equal 1, lines.match_count end end + + def test_preview_wrap_sign_between_ansi_fragments + tmux.send_keys %(seq 1 | #{FZF} --preview 'echo -e "\\x1b[33m1234567890 \\x1b[mhello"; echo -e "\\x1b[33m1234567890 \\x1b[mhello"' --preview-window 10,wrap-word), :Enter + tmux.until do |lines| + assert_equal 1, lines.match_count + assert_equal 2, lines.count { |line| line.include?('│ 1234567890 │') } + assert_equal 2, lines.count { |line| line.include?('│ ↳ hello │') } + end + end + + def test_preview_wrap_sign_between_ansi_fragments_overflow + tmux.send_keys %(seq 1 | #{FZF} --preview 'echo -e "\\x1b[33m1234567890 \\x1b[mhello"; echo -e "\\x1b[33m1234567890 \\x1b[mhello"' --preview-window 2,wrap-word), :Enter + tmux.until do |lines| + assert_equal 1, lines.match_count + assert_equal 2, lines.count { |line| line.include?('│ 12 │') } + assert_equal 0, lines.count { |line| line.include?('│ h') } + end + end + + def test_preview_wrap_sign_between_ansi_fragments_overflow2 + tmux.send_keys %(seq 1 | #{FZF} --preview 'echo -e "\\x1b[33m1234567890 \\x1b[mhello"; echo -e "\\x1b[33m1234567890 \\x1b[mhello"' --preview-window 1,wrap-word), :Enter + tmux.until do |lines| + assert_equal 1, lines.match_count + assert_equal 2, lines.count { |line| line.include?('│ 1 │') } + assert_equal 0, lines.count { |line| line.include?('│ h') } + end + end end