Skip to content

fix(renderer): fix cursor jumping #1377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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