Weird jumps when collapsing node #1374
Replies: 3 comments 20 replies
-
As we now have I think many of the workaround-ish code to save the cursor position was doing a race condition which I should have solved with #1355 so we should have consistent and predictable results now. But I'm not the one who wrote (nor have I ever interacted with) this code so I can't say for sure. Redirecting this to @cseickel |
Beta Was this translation helpful? Give feedback.
-
Why?This chunk of code is not about saving the top line at all, it is the opposite. It moves the top line if either of these situations occur:
Fixing the scrolled down to far problem is mostly about opening and closing folders which change the overall size of the tree and can lead to be scrolled down when you don't need to be. The "requested extra padding" is for the sake of the search popup which floats over top of the bottom of the window. You need the extra padding to ensure that the focused node is not under the floating window. How?Given that understanding, I will attempt to walk through the code. -- 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")
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
I could have misinterpreted, even though I think I did write this code. |
Beta Was this translation helpful? Give feedback.
-
I reported this before, but it's not completely fixed: #996
I tracked it down to this piece of codes:
neo-tree.nvim/lua/neo-tree/ui/renderer.lua
Lines 542 to 547 in 459c603
If I comment it out, everything works perfectly as expected.
Anybody knows what that piece of code does?
neo-tree.nvim/lua/neo-tree/ui/renderer.lua
Line 542 in 459c603
This moves the current node at the bottom of screen.
neo-tree.nvim/lua/neo-tree/ui/renderer.lua
Line 546 in 459c603
Then this moves another line at the top of screen.
These causes unnecessary jumps and it's very problematic.
Beta Was this translation helpful? Give feedback.
All reactions