Fix cyclic scrolling with non-zero preview header lines

e.g. fzf --preview-window 'cycle,~2' --preview 'echo foo; echo bar; seq 100'
This commit is contained in:
Junegunn Choi 2023-01-04 22:00:00 +09:00
parent 5798145581
commit 03d02d67f7
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -2652,10 +2652,12 @@ func (t *Terminal) Loop() {
} }
t.previewer.following = false t.previewer.following = false
numLines := len(t.previewer.lines) numLines := len(t.previewer.lines)
headerLines := t.previewOpts.headerLines
if t.previewOpts.cycle { if t.previewOpts.cycle {
newOffset = (newOffset + numLines) % numLines offsetRange := numLines - headerLines
newOffset = ((newOffset-headerLines)+offsetRange)%offsetRange + headerLines
} }
newOffset = util.Constrain(newOffset, t.previewOpts.headerLines, numLines-1) newOffset = util.Constrain(newOffset, headerLines, numLines-1)
if t.previewer.offset != newOffset { if t.previewer.offset != newOffset {
t.previewer.offset = newOffset t.previewer.offset = newOffset
req(reqPreviewRefresh) req(reqPreviewRefresh)