Skip to content
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

fix(render): add a condition to check bufname already exists or not #1429

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion lua/neo-tree/ui/renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,15 @@ M.acquire_window = function(state)
end

if win ~= nil then
vim.api.nvim_buf_set_name(state.bufnr, bufname)
local bufnameExists = false
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_buf_is_loaded(bufnr) or vim.api.nvim_buf_get_name(bufnr) == bufname then
bufnameExists = true
end
end
if not bufnameExists then
Copy link
Contributor

@cseickel cseickel Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't just not give the buffer a name. The name is important. This will fix one bug while creating new ones.

I've been meaning to circle back on this myself but haven't found the time. See these for history f you want to spend the time:

#1418
#1408
#1406
#1390

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I'm just reusing the already existed buffer name, that will fix this error:
[Neo-tree ERROR] debounce filesystem_navigate error: ...e-bug/plugins/neo-tree.nvim/lua/neo-tree/ui/renderer.lua:1036: Vim:E95: Buffer with this name already exists
Since I'm using my own fork with these changes, I'm not getting any unexpected error or behavior. I checked almost features of Neotree in Arch Linux. I think everything is fine!

vim.api.nvim_buf_set_name(state.bufnr, bufname)
end
vim.api.nvim_set_current_win(state.winid)
-- Used to track the position of the cursor within the tree as it gains and loses focus
win:on({ "BufDelete" }, function()
Expand Down