Skip to content
Myr

Fix preview follow/scroll with long wrapped lines

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

Fixes bugs reported in https://github.com/junegunn/fzf/pull/4703: * Clamp followOffset return value to avoid going past the end of lines * Account for t.previewed.filled when determining scrollability

authored by Junegunn Choi · committed by Junegunn Choi · parent e7300fe · Browse files · 2 files+17 added−3 removed
This commit

State

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

Diff stats

2 files+17 added−3 removed

  • tests:+14 added−0 removed
  • other:+3 added−3 removed

2 files+17 added−3 removed

modified:src/terminal.go+3 added-3 removed
4221 unmodified lines
4222 visualLines := 04223 for i := len(body) - 1; i >= 0; i-- {4224 h := t.previewLineHeight(body[i], maxWidth)4225 if visualLines+h > height {4226 return headerLines + i + 14226 return min(len(lines)-1, headerLines+i+1)4227 }4228 visualLines += h4229 }4230 return headerLines
289 unmodified lines
4520 break Loop4521 }4522 }45234524 t.previewer.scrollable = t.previewer.scrollable || t.pwindow.Y() == height-1 && t.pwindow.X() == t.pwindow.Width()4524 t.previewer.scrollable = t.previewer.scrollable || t.pwindow.Y() == height-1 && t.pwindow.X() == t.pwindow.Width() || t.previewed.filled4525 if fillRet == tui.FillNextLine {4526 continue4527 } else if fillRet == tui.FillSuspend {4528 t.previewed.filled = true
14 unmodified lines
4543 }4544 }4545 lineNo++4546 }4547 t.previewer.scrollable = t.previewer.scrollable || index < len(lines)-14547 t.previewer.scrollable = t.previewer.scrollable || t.previewed.filled || index < len(lines)-14548 t.previewed.image = image4549 t.previewed.wireframe = wireframe4550}4551
3259 unmodified lines
modified:test/test_preview.rb+14 added
391 unmodified lines
392 assert_includes lines[idx + 2], '│ ↳ │'393 end394 end395396 def test_preview_follow_wrap_long_line397 tmux.send_keys %(seq 1 | #{FZF} --preview "seq 2; yes yes | head -10000 | tr '\n' ' '" --preview-window follow,wrap --bind up:preview-up,down:preview-down), :Enter398 tmux.until do |lines|399 assert_equal 1, lines.match_count400 assert lines.any_include?('3/3 │')401 end402 tmux.send_keys :Up403 tmux.until { |lines| assert lines.any_include?('2/3 │') }404 tmux.send_keys :Up405 tmux.until { |lines| assert lines.any_include?('1/3 │') }406 tmux.send_keys :Down407 tmux.until { |lines| assert lines.any_include?('2/3 │') }408 end409410 def test_close411 tmux.send_keys "seq 100 | #{FZF} --preview 'echo foo' --bind ctrl-c:close", :Enter412 tmux.until { |lines| assert_equal 100, lines.match_count }413 tmux.until { |lines| assert_includes lines[1], 'foo' }
213 unmodified lines