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:
Junegunn Choi
2026-03-06 19:21:22 +09:00
parent e7300fe300
commit 0b08f0dea0
2 changed files with 17 additions and 3 deletions

View File

@@ -4223,7 +4223,7 @@ func (t *Terminal) followOffset() int {
for i := len(body) - 1; i >= 0; i-- {
h := t.previewLineHeight(body[i], maxWidth)
if visualLines+h > height {
return headerLines + i + 1
return min(len(lines)-1, headerLines+i+1)
}
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 {
continue
} else if fillRet == tui.FillSuspend {
@@ -4544,7 +4544,7 @@ Loop:
}
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.wireframe = wireframe
}