From d6b0a3d884592ef7d1b188df260ef50ba016e121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B-Cosmin=20Nicula?= Date: Mon, 10 Jun 2024 13:32:33 +0300 Subject: [PATCH] Fix scrolling logic when header is present --- fuzzyfinder.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fuzzyfinder.go b/fuzzyfinder.go index 7b1330b..2eb75c0 100644 --- a/fuzzyfinder.go +++ b/fuzzyfinder.go @@ -490,6 +490,11 @@ func (f *finder) readKey(ctx context.Context) error { // Max number of lines to scroll by using PgUp and PgDn var pageScrollBy = screenHeight - 3 + occupiedLines := 2 + if len(f.opt.header) != 0 { + occupiedLines++ + } + switch e := e.(type) { case *tcell.EventKey: switch e.Key() { @@ -554,7 +559,7 @@ func (f *finder) readKey(ctx context.Context) error { if f.state.y+1 < matchedLinesCount { f.state.y++ } - if f.state.cursorY+1 < min(matchedLinesCount, screenHeight-2) { + if f.state.cursorY+1 < min(matchedLinesCount, screenHeight-occupiedLines) { f.state.cursorY++ } case tcell.KeyDown, tcell.KeyCtrlJ, tcell.KeyCtrlN: @@ -607,7 +612,7 @@ func (f *finder) readKey(ctx context.Context) error { f.term.Clear() width, height := f.term.Size() - itemAreaHeight := height - 2 - 1 + itemAreaHeight := height - occupiedLines - 1 if itemAreaHeight >= 0 && f.state.cursorY > itemAreaHeight { f.state.cursorY = itemAreaHeight }