Skip to content

Commit b92220e

Browse files
committed
fix(previewer): preview-page-up top of buffer (closes #1220)
1 parent ae609e6 commit b92220e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lua/fzf-lua/previewer/builtin.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,20 @@ function Previewer.base:scroll(direction)
356356

357357
if input then
358358
pcall(vim.api.nvim_win_call, preview_winid, function()
359+
-- ctrl-b (page-up) behaves in a non consistent way, unlike ctrl-u, if it can't
360+
-- scroll a full page upwards it won't move the cursor, if the cursor is within
361+
-- the first page it will still move the cursor to the bottom of the page (!?)
362+
-- we therefore need special handling for both scenarios with `ctrl-b`:
363+
-- (1) If the cursor is at line 1, do nothing
364+
-- (2) Else, test the cursor before and after, if the new position is further
365+
-- down the buffer than the original, we're in the first page ,goto line 1
366+
local is_ctrl_b = string.byte(input, 1) == 2
367+
local pos = is_ctrl_b and vim.api.nvim_win_get_cursor(0)
368+
if is_ctrl_b and pos[1] == 1 then return end
359369
vim.cmd([[norm! ]] .. input)
370+
if is_ctrl_b and pos[1] <= vim.api.nvim_win_get_cursor(0)[1] then
371+
vim.api.nvim_win_set_cursor(0, { 1, pos[2] })
372+
end
360373
utils.zz()
361374
end)
362375
end

0 commit comments

Comments
 (0)