Skip to content

Commit cc388da

Browse files
authored
fix: wrong size buffer width with NvimTree (#144)
## 📃 Summary contributes to #133 closes #142 The width of the tree was still taken into account with the `reopen = false` option. We now reset the registered trees width before computing the padding, if `reopen` is `false`. ### Other changes The `close` option doesn't make sense actually, we close it anyway, a single option is enough. ## 📸 Preview ### before <img width="1280" alt="Screenshot 2023-01-15 at 21 36 44" src="https://user-images.githubusercontent.com/20689156/212565890-aff580d7-c526-4d6e-85d0-b15482b9c9ca.png"> ### after <img width="1280" alt="Screenshot 2023-01-15 at 21 37 32" src="https://user-images.githubusercontent.com/20689156/212565930-e433a8d4-629f-4012-b248-2cd815c6951b.png">
1 parent 5e215cf commit cc388da

File tree

6 files changed

+13
-18
lines changed

6 files changed

+13
-18
lines changed

README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,7 @@ require("no-neck-pain").setup({
187187
NvimTree = {
188188
-- The position of the tree, either `left` or `right`.
189189
position = "left",
190-
-- When `true`, we close NvimTree if it's currently open when enabling the plugin.
191-
close = true,
192-
-- Paired with the `close` parameter, when `false` we don't re-open the side tree.
190+
-- When `true`, if the tree was opened before enabling the plugin, we will reopen it.
193191
reopen = true,
194192
},
195193
-- @link https://github.com/mbbill/undotree

doc/no-neck-pain.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,7 @@ Default values:
174174
NvimTree = {
175175
-- The position of the tree, either `left` or `right`.
176176
position = "left",
177-
-- When `true`, we close NvimTree if it's currently open when enabling the plugin.
178-
close = true,
179-
-- Paired with the `close` parameter, when `false` we don't re-open the side tree.
177+
-- When `true`, if the tree was opened before enabling the plugin, we will reopen it.
180178
reopen = true,
181179
},
182180
-- @link https://github.com/mbbill/undotree

lua/no-neck-pain/config.lua

+1-3
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ NoNeckPain.options = {
152152
NvimTree = {
153153
-- The position of the tree, either `left` or `right`.
154154
position = "left",
155-
-- When `true`, we close NvimTree if it's currently open when enabling the plugin.
156-
close = true,
157-
-- Paired with the `close` parameter, when `false` we don't re-open the side tree.
155+
-- When `true`, if the tree was opened before enabling the plugin, we will reopen it.
158156
reopen = true,
159157
},
160158
-- @link https://github.com/mbbill/undotree

lua/no-neck-pain/util/win.lua

+10-6
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ function W.createSideBuffers(wins)
4040
}
4141

4242
-- we close the side tree if it's already opened to prevent unwanted layout issue.
43-
if
44-
wins.external.trees.NvimTree.id ~= nil
45-
and _G.NoNeckPain.config.integrations.NvimTree.close
46-
then
43+
if wins.external.trees.NvimTree.id ~= nil then
4744
integrations.NvimTree = true
4845
vim.cmd("NvimTreeClose")
4946
end
@@ -120,8 +117,15 @@ function W.createSideBuffers(wins)
120117
end
121118

122119
-- if we've closed the user side tree but they still want it to be opened.
123-
if integrations.NvimTree and _G.NoNeckPain.config.integrations.NvimTree.reopen == true then
124-
vim.cmd("NvimTreeOpen")
120+
if integrations.NvimTree then
121+
if _G.NoNeckPain.config.integrations.NvimTree.reopen == true then
122+
vim.cmd("NvimTreeOpen")
123+
else
124+
wins.external.trees.NvimTree = {
125+
id = nil,
126+
width = 0,
127+
}
128+
end
125129
end
126130

127131
return W.resizeOrCloseSideBuffers("W.createSideBuffers", wins)

tests/test_API.lua

-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ T["setup"]["sets exposed methods and default options value"] = function()
113113
end
114114

115115
eq_config(child, "integrations.NvimTree.position", "left")
116-
eq_config(child, "integrations.NvimTree.close", true)
117116
eq_config(child, "integrations.NvimTree.reopen", true)
118117
eq_config(child, "integrations.undotree.position", "left")
119118
end

tests/test_integrations.lua

-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ T["setup"]["overrides default values"] = function()
2222
integrations = {
2323
NvimTree = {
2424
position = "right",
25-
close = false,
2625
reopen = false,
2726
},
2827
undotree = {
@@ -32,7 +31,6 @@ T["setup"]["overrides default values"] = function()
3231
})]])
3332

3433
eq_config(child, "integrations.NvimTree.position", "right")
35-
eq_config(child, "integrations.NvimTree.close", false)
3634
eq_config(child, "integrations.NvimTree.reopen", false)
3735
eq_config(child, "integrations.undotree.position", "right")
3836
end

0 commit comments

Comments
 (0)