@@ -537,16 +537,13 @@ M.focus_node = function(state, id, do_not_focus_window, relative_movement, botto
537537 -- make sure we are not scrolled down if it can all fit on the screen
538538 local lines = vim .api .nvim_buf_line_count (state .bufnr )
539539 local win_height = vim .api .nvim_win_get_height (state .winid )
540- local expected_bottom_line = math.min (lines , linenr + 5 ) + bottom_scroll_padding
541- if expected_bottom_line > win_height then
542- execute_win_command (" normal! zb" )
543- local top = vim .fn .line (" w0" , state .winid )
544- local bottom = vim .fn .line (" w$" , state .winid )
545- local offset_top = top + (expected_bottom_line - bottom )
546- execute_win_command (" normal! " .. offset_top .. " zt" )
540+ local virtual_bottom_line = vim .fn .line (" w0" , state .winid ) + win_height - bottom_scroll_padding
541+ if virtual_bottom_line <= linenr then
542+ execute_win_command (" normal! " .. (linenr + bottom_scroll_padding ) .. " zb" )
543+ pcall (vim .api .nvim_win_set_cursor , state .winid , { linenr , col })
544+ elseif virtual_bottom_line > lines then
545+ execute_win_command (" normal! " .. (lines + bottom_scroll_padding ) .. " zb" )
547546 pcall (vim .api .nvim_win_set_cursor , state .winid , { linenr , col })
548- elseif win_height > linenr then
549- execute_win_command (" normal! zb" )
550547 elseif linenr < (win_height / 2 ) then
551548 execute_win_command (" normal! zz" )
552549 end
0 commit comments