-
Notifications
You must be signed in to change notification settings - Fork 252
fix(renderer): check if current buffer is loaded #1418
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
Changes from all commits
19e3319
7e1c333
934935a
5568709
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,13 +163,15 @@ M.close = function(state, focus_prior_window) | |
end | ||
state.winid = nil | ||
end | ||
local bufnr = utils.get_value(state, "bufnr", 0, true) | ||
state.bufnr = nil | ||
vim.schedule(function() | ||
if bufnr > 0 and vim.api.nvim_buf_is_valid(bufnr) then | ||
vim.api.nvim_buf_delete(bufnr, { force = true }) | ||
end | ||
end) | ||
if window_existed then | ||
local bufnr = utils.get_value(state, "bufnr", 0, true) | ||
state.bufnr = nil | ||
vim.schedule(function() | ||
if bufnr > 0 and vim.api.nvim_buf_is_valid(bufnr) then | ||
vim.api.nvim_buf_delete(bufnr, { force = true }) | ||
end | ||
end) | ||
end | ||
return window_existed | ||
end | ||
|
||
|
@@ -778,6 +780,7 @@ create_tree = function(state) | |
state.tree = NuiTree({ | ||
ns_id = highlights.ns_id, | ||
winid = state.winid, | ||
bufnr = state.bufnr, | ||
get_node_id = function(node) | ||
return node.id | ||
end, | ||
|
@@ -1010,6 +1013,9 @@ M.acquire_window = function(state) | |
vim.api.nvim_win_set_buf(state.winid, state.bufnr) | ||
else | ||
close_old_window() | ||
if state.bufnr and vim.api.nvim_buf_is_valid(state.bufnr) then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Also, if i remember correctly, the original code from a few months ago already did what we are slowly getting back to, which is to immediately attempt to delete the buffer and then schedule a delete for later only if we get a specific error. I think the right place to make this fix is in the |
||
vim.api.nvim_buf_delete(state.bufnr, { force = true }) | ||
end | ||
win = NuiSplit(win_options) | ||
win:mount() | ||
state.bufnr = win.bufnr | ||
|
@@ -1087,7 +1093,7 @@ M.window_exists = function(state) | |
window_exists = false | ||
elseif position == "current" then | ||
window_exists = vim.api.nvim_win_is_valid(winid) | ||
and vim.api.nvim_buf_is_valid(bufnr) | ||
and vim.api.nvim_buf_is_loaded(bufnr) | ||
and vim.api.nvim_win_get_buf(winid) == bufnr | ||
else | ||
local isvalid = M.is_window_valid(winid) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it matter if the window existed? Why should a buffer be allowed to remain if the window was closed by some other means, but not if it was closed by this function?
Also, why is it always scheduled even though it usually should be deleted synchronously?
I think the code from 3.22 was already correct and would fix this issue and we should just go back to that:
neo-tree.nvim/lua/neo-tree/ui/renderer.lua
Lines 167 to 175 in 8afbb06
Whatever the other edge case was which the changes were trying to fix should be handled another way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have confirmed that the old code works correctly and the bug in #1415 was the direct result of changing that code. I'm going to close this because reverting that code is the real fix.