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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent duplicate buffer name error with setNames #186

Merged
merged 2 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions lua/no-neck-pain/wins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ function W.createSideBuffers(tab)
local id = vim.api.nvim_get_current_win()

if _G.NoNeckPain.config.buffers.setNames then
local exist = vim.fn.bufnr("no-neck-pain-" .. side)

if exist ~= -1 then
vim.api.nvim_buf_delete(exist, { force = true })
end

vim.api.nvim_buf_set_name(0, "no-neck-pain-" .. side)
end

Expand Down
17 changes: 17 additions & 0 deletions tests/test_buffers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,23 @@ end

T["left/right"] = MiniTest.new_set()

T["left/right"]["setNames doesn't throw when re-creating side buffers"] = function()
child.lua([[require('no-neck-pain').setup({width=50, buffers={setNames=true}})]])

-- enable
child.cmd([[NoNeckPain]])

eq_buf_width(child, "tabs[1].wins.main.left", 15)
eq_buf_width(child, "tabs[1].wins.main.right", 15)

-- toggle
child.cmd([[NoNeckPain]])
child.cmd([[NoNeckPain]])

eq_buf_width(child, "tabs[1].wins.main.left", 15)
eq_buf_width(child, "tabs[1].wins.main.right", 15)
end

T["left/right"]["have the same width"] = function()
child.lua([[
require('no-neck-pain').setup({width=50})
Expand Down