File tree 1 file changed +13
-0
lines changed 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -356,7 +356,20 @@ function Previewer.base:scroll(direction)
356
356
357
357
if input then
358
358
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
359
369
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
360
373
utils .zz ()
361
374
end )
362
375
end
You can’t perform that action at this time.
0 commit comments