mirror of
https://github.com/junegunn/fzf.git
synced 2026-08-12 02:42:37 +08:00
Fix preview follow/scroll with long wrapped lines
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
This commit is contained in:
+3
-3
@@ -4223,7 +4223,7 @@ func (t *Terminal) followOffset() int {
|
|||||||
for i := len(body) - 1; i >= 0; i-- {
|
for i := len(body) - 1; i >= 0; i-- {
|
||||||
h := t.previewLineHeight(body[i], maxWidth)
|
h := t.previewLineHeight(body[i], maxWidth)
|
||||||
if visualLines+h > height {
|
if visualLines+h > height {
|
||||||
return headerLines + i + 1
|
return min(len(lines)-1, headerLines+i+1)
|
||||||
}
|
}
|
||||||
visualLines += h
|
visualLines += h
|
||||||
}
|
}
|
||||||
@@ -4521,7 +4521,7 @@ Loop:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
t.previewer.scrollable = t.previewer.scrollable || t.pwindow.Y() == height-1 && t.pwindow.X() == t.pwindow.Width()
|
t.previewer.scrollable = t.previewer.scrollable || t.pwindow.Y() == height-1 && t.pwindow.X() == t.pwindow.Width() || t.previewed.filled
|
||||||
if fillRet == tui.FillNextLine {
|
if fillRet == tui.FillNextLine {
|
||||||
continue
|
continue
|
||||||
} else if fillRet == tui.FillSuspend {
|
} else if fillRet == tui.FillSuspend {
|
||||||
@@ -4544,7 +4544,7 @@ Loop:
|
|||||||
}
|
}
|
||||||
lineNo++
|
lineNo++
|
||||||
}
|
}
|
||||||
t.previewer.scrollable = t.previewer.scrollable || index < len(lines)-1
|
t.previewer.scrollable = t.previewer.scrollable || t.previewed.filled || index < len(lines)-1
|
||||||
t.previewed.image = image
|
t.previewed.image = image
|
||||||
t.previewed.wireframe = wireframe
|
t.previewed.wireframe = wireframe
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -393,6 +393,20 @@ class TestPreview < TestInteractive
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_preview_follow_wrap_long_line
|
||||||
|
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), :Enter
|
||||||
|
tmux.until do |lines|
|
||||||
|
assert_equal 1, lines.match_count
|
||||||
|
assert lines.any_include?('3/3 │')
|
||||||
|
end
|
||||||
|
tmux.send_keys :Up
|
||||||
|
tmux.until { |lines| assert lines.any_include?('2/3 │') }
|
||||||
|
tmux.send_keys :Up
|
||||||
|
tmux.until { |lines| assert lines.any_include?('1/3 │') }
|
||||||
|
tmux.send_keys :Down
|
||||||
|
tmux.until { |lines| assert lines.any_include?('2/3 │') }
|
||||||
|
end
|
||||||
|
|
||||||
def test_close
|
def test_close
|
||||||
tmux.send_keys "seq 100 | #{FZF} --preview 'echo foo' --bind ctrl-c:close", :Enter
|
tmux.send_keys "seq 100 | #{FZF} --preview 'echo foo' --bind ctrl-c:close", :Enter
|
||||||
tmux.until { |lines| assert_equal 100, lines.match_count }
|
tmux.until { |lines| assert_equal 100, lines.match_count }
|
||||||
|
|||||||
Reference in New Issue
Block a user