Skip to content

Commit d924e1a

Browse files
committed
fix(statusline): Fixdd issues with detaching from attached buffers
fix(statusline): Fixed issues with detaching from attached buffers
1 parent 339a4ca commit d924e1a

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

lua/bars/statuscolumn.lua

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local components = require("bars.components.statuscolumn");
44
---@type statuscolumn.config
55
statuscolumn.config = {
66
ignore_filetypes = {},
7-
ignore_buftypes = { "nofile" },
7+
ignore_buftypes = { "nofile", "help" },
88

99
default = {
1010
parts = {
@@ -201,6 +201,34 @@ statuscolumn.render = function (buffer, window)
201201
---|fE
202202
end
203203

204+
--- Detaches from {buffer}.
205+
---@param buffer integer
206+
statuscolumn.detach = function (buffer)
207+
---|fS
208+
209+
if type(buffer) ~= "number" then
210+
return;
211+
elseif vim.api.nvim_buf_is_loaded(buffer) == false then
212+
return;
213+
elseif vim.api.nvim_buf_is_valid(buffer) == false then
214+
return;
215+
end
216+
217+
for w, win in ipairs(statuscolumn.state.attached_windows) do
218+
if vim.api.nvim_win_get_buf(win) ~= buffer then
219+
goto continue;
220+
end
221+
222+
vim.w[win].__scID = nil;
223+
vim.wo[win].statuscolumn = "";
224+
table.remove(statuscolumn.state.attached_windows, w);
225+
226+
::continue::
227+
end
228+
229+
---|fE
230+
end
231+
204232
--- Attaches the statuscolumn module to the windows
205233
--- of a buffer.
206234
---@param buffer integer
@@ -210,14 +238,19 @@ statuscolumn.attach = function (buffer)
210238
local ft, bt = vim.bo[buffer].ft, vim.bo[buffer].bt;
211239

212240
if type(buffer) ~= "number" then
241+
statuscolumn.detach(buffer);
213242
return;
214243
elseif vim.api.nvim_buf_is_loaded(buffer) == false then
244+
statuscolumn.detach(buffer);
215245
return;
216246
elseif vim.api.nvim_buf_is_valid(buffer) == false then
247+
statuscolumn.detach(buffer);
217248
return;
218249
elseif vim.list_contains(statuscolumn.config.ignore_filetypes, ft) then
250+
statuscolumn.detach(buffer);
219251
return;
220252
elseif vim.list_contains(statuscolumn.config.ignore_buftypes, bt) then
253+
statuscolumn.detach(buffer);
221254
return;
222255
end
223256

lua/bars/statusline.lua

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,34 @@ statusline.render = function (buffer, window)
472472
---|fE
473473
end
474474

475+
--- Detaches from {buffer}.
476+
---@param buffer integer
477+
statusline.detach = function (buffer)
478+
---|fS
479+
480+
if type(buffer) ~= "number" then
481+
return;
482+
elseif vim.api.nvim_buf_is_loaded(buffer) == false then
483+
return;
484+
elseif vim.api.nvim_buf_is_valid(buffer) == false then
485+
return;
486+
end
487+
488+
for w, win in ipairs(statusline.state.attached_windows) do
489+
if vim.api.nvim_win_get_buf(win) ~= buffer then
490+
goto continue;
491+
end
492+
493+
vim.w[win].__slID = nil;
494+
vim.wo[win].statusline = "";
495+
table.remove(statusline.state.attached_windows, w);
496+
497+
::continue::
498+
end
499+
500+
---|fE
501+
end
502+
475503
--- Attaches the statusline module to the windows
476504
--- of a buffer.
477505
---@param buffer integer
@@ -481,14 +509,19 @@ statusline.attach = function (buffer)
481509
local ft, bt = vim.bo[buffer].ft, vim.bo[buffer].bt;
482510

483511
if type(buffer) ~= "number" then
512+
statusline.detach(buffer);
484513
return;
485514
elseif vim.api.nvim_buf_is_loaded(buffer) == false then
515+
statusline.detach(buffer);
486516
return;
487517
elseif vim.api.nvim_buf_is_valid(buffer) == false then
518+
statusline.detach(buffer);
488519
return;
489520
elseif vim.list_contains(statusline.config.ignore_filetypes, ft) then
521+
statusline.detach(buffer);
490522
return;
491523
elseif vim.list_contains(statusline.config.ignore_buftypes, bt) then
524+
statusline.detach(buffer);
492525
return;
493526
end
494527

0 commit comments

Comments
 (0)