Skip to content

Commit

Permalink
fix(renderer): fix cursor jumping (#1377)
Browse files Browse the repository at this point in the history
  • Loading branch information
pysan3 committed Mar 6, 2024
1 parent 459c603 commit dcb63ab
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lua/neo-tree/ui/renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -537,16 +537,13 @@ M.focus_node = function(state, id, do_not_focus_window, relative_movement, botto
-- make sure we are not scrolled down if it can all fit on the screen
local lines = vim.api.nvim_buf_line_count(state.bufnr)
local win_height = vim.api.nvim_win_get_height(state.winid)
local expected_bottom_line = math.min(lines, linenr + 5) + bottom_scroll_padding
if expected_bottom_line > win_height then
execute_win_command("normal! zb")
local top = vim.fn.line("w0", state.winid)
local bottom = vim.fn.line("w$", state.winid)
local offset_top = top + (expected_bottom_line - bottom)
execute_win_command("normal! " .. offset_top .. "zt")
local virtual_bottom_line = vim.fn.line("w0", state.winid) + win_height - bottom_scroll_padding
if virtual_bottom_line <= linenr then
execute_win_command("normal! " .. (linenr + bottom_scroll_padding) .. "zb")
pcall(vim.api.nvim_win_set_cursor, state.winid, { linenr, col })
elseif virtual_bottom_line > lines then
execute_win_command("normal! " .. (lines + bottom_scroll_padding) .. "zb")
pcall(vim.api.nvim_win_set_cursor, state.winid, { linenr, col })
elseif win_height > linenr then
execute_win_command("normal! zb")
elseif linenr < (win_height / 2) then
execute_win_command("normal! zz")
end
Expand Down

0 comments on commit dcb63ab

Please sign in to comment.