Skip to content

Commit 7ad7fd1

Browse files
committed
fix(winbar): Wrapped callback functions for detaching
1 parent 7f18b76 commit 7ad7fd1

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

lua/bars/winbar.lua

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -711,29 +711,33 @@ winbar.detach = function (window)
711711
---|fS
712712

713713
vim.schedule(function ()
714-
vim.w[window].__wbID = nil;
715-
716-
--- Cached winbar.
717-
---@type string | nil
718-
local _wb = vim.w[window].__winbar or vim.g.__winbar or "";
719-
720-
if _wb == "" or _wb == nil then
721-
--- Reset winbar.
722-
vim.api.nvim_win_call(window, function ()
723-
vim.cmd("set winbar&");
724-
end);
725-
else
726-
vim.api.nvim_set_option_value(
727-
"winbar",
728-
_wb,
729-
{
730-
scope = "local",
731-
win = window
732-
}
733-
);
734-
end
714+
pcall(function ()
715+
vim.w[window].__wbID = nil;
716+
717+
--- Cached winbar.
718+
---@type string | nil
719+
local _wb = vim.w[window].__winbar or vim.g.__winbar or "";
720+
721+
if _wb == "" or _wb == nil then
722+
--- Reset winbar.
723+
vim.api.nvim_win_call(window, function ()
724+
pcall(function ()
725+
vim.cmd("set winbar&");
726+
end);
727+
end);
728+
else
729+
pcall(vim.api.nvim_set_option_value,
730+
"winbar",
731+
_wb,
732+
{
733+
scope = "local",
734+
win = window
735+
}
736+
);
737+
end
735738

736-
winbar.state.attached_windows[window] = false;
739+
winbar.state.attached_windows[window] = false;
740+
end)
737741
end);
738742

739743
---|fE

0 commit comments

Comments
 (0)