Skip to content

Commit 6c26f92

Browse files
committed
fix(statuscolumn): Added check for module state before attching to new buffer
feat(statuscolumn): Added Enabling & Disabling commands
1 parent b4baa6d commit 6c26f92

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

lua/bars/statuscolumn.lua

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ end
360360
statuscolumn.can_attach = function (win)
361361
if vim.api.nvim_win_is_valid(win) == false then
362362
return false;
363+
elseif statuscolumn.state.attached_windows[win] == false then
364+
return false;
365+
elseif statuscolumn.state.enable == false then
366+
return false;
363367
end
364368

365369
local buffer = vim.api.nvim_win_get_buf(win);
@@ -423,6 +427,10 @@ end
423427

424428
--- Attaches globally.
425429
statuscolumn.global_attach = function ()
430+
if statuscolumn.state.enable == false then
431+
return;
432+
end
433+
426434
for _, window in ipairs(vim.api.nvim_list_wins()) do
427435
statuscolumn.update_id(window);
428436
end
@@ -446,6 +454,8 @@ statuscolumn.clean = function ()
446454
---|fE
447455
end
448456

457+
----------------------------------------------------------------------
458+
449459
--- Toggles state of given window.
450460
---@param window integer
451461
statuscolumn.toggle = function (window)
@@ -454,7 +464,7 @@ statuscolumn.toggle = function (window)
454464
elseif statuscolumn.state.attached_windows[window] == true then
455465
statuscolumn.detach(window);
456466
else
457-
statuscolumn.attach(window);
467+
statuscolumn.attach(window);
458468
end
459469
end
460470

@@ -471,6 +481,52 @@ statuscolumn.Toggle = function ()
471481
statuscolumn.state.enable = not statuscolumn.state.enable;
472482
end
473483

484+
----------------------------------------------------------------------
485+
486+
--- Enables statuscolumn for `window`.
487+
---@param window integer
488+
statuscolumn.enable = function (window)
489+
if type(window) ~= "number" or statuscolumn.state.attached_windows[window] == nil then
490+
return;
491+
end
492+
493+
statuscolumn.attach(window);
494+
end
495+
496+
--- Enables *all* attached windows.
497+
statuscolumn.Enable = function ()
498+
statuscolumn.state.enable = true;
499+
500+
for window, state in pairs(statuscolumn.state.attached_windows) do
501+
if state ~= true then
502+
statuscolumn.attach(window);
503+
end
504+
end
505+
end
506+
507+
--- Disables statuscolumn for `window`.
508+
---@param window integer
509+
statuscolumn.disable = function (window)
510+
if type(window) ~= "number" or statuscolumn.state.attached_windows[window] == nil then
511+
return;
512+
end
513+
514+
statuscolumn.detach(window);
515+
end
516+
517+
--- Disables *all* attached windows.
518+
statuscolumn.Disable = function ()
519+
for window, state in pairs(statuscolumn.state.attached_windows) do
520+
if state ~= false then
521+
statuscolumn.detach(window);
522+
end
523+
end
524+
525+
statuscolumn.state.enable = false;
526+
end
527+
528+
----------------------------------------------------------------------
529+
474530
--- Sets up the statuscolumn module.
475531
---@param config statuscolumn.config | nil
476532
statuscolumn.setup = function (config)

0 commit comments

Comments
 (0)