Skip to content

Commit 909ba6c

Browse files
committed
feat(core): Mode changes now update the bars & lines
doc: Added some comments
1 parent f433250 commit 909ba6c

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

plugin/bars.lua

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ vim.g.__tabline = utils.constant(vim.o.tabline);
1717

1818
---|fE
1919

20+
--- Attach various bars & lines globally if
21+
--- `global = true`.
2022
if require("bars").config.global == true then
2123
require("bars.statuscolumn").global_attach();
2224
require("bars.statusline").global_attach();
@@ -27,13 +29,23 @@ else
2729
require("bars.tabline").attach();
2830
end
2931

32+
--- Attach to new Windows.
33+
---
34+
--- Also rum this when a buffer is displayed
35+
--- in a window as the filetype/buftype may
36+
--- could have changed.
37+
---
38+
--- `VimEnter` is used because the other events
39+
--- don't trigger when entering Neovim.
3040
vim.api.nvim_create_autocmd({
3141
"VimEnter",
3242

3343
"WinNew",
3444
"BufWinEnter"
3545
}, {
3646
callback = function ()
47+
---|fS
48+
3749
require("bars.statusline").clean();
3850
require("bars.statuscolumn").clean();
3951
require("bars.winbar").clean();
@@ -47,12 +59,22 @@ vim.api.nvim_create_autocmd({
4759
end
4860

4961
require("bars.tabline").attach();
50-
end)
62+
end);
63+
64+
---|fE
5165
end
5266
});
5367

68+
--- When the 'filetype' or 'buftype' option is set
69+
--- we must clean up any window that has become invalid
70+
--- and update the configuration of existing windows.
71+
---
72+
--- TODO, Check if this causes performance issues
73+
--- with large amount of windows.
5474
vim.api.nvim_create_autocmd({ "OptionSet" }, {
5575
callback = function ()
76+
---|fS
77+
5678
local option = vim.fn.expand("<amatch>");
5779
local valid_options = { "filetype", "buftype" };
5880

@@ -74,6 +96,27 @@ vim.api.nvim_create_autocmd({ "OptionSet" }, {
7496
end
7597

7698
require("bars.tabline").attach();
77-
end)
99+
end);
100+
101+
---|fE
102+
end
103+
});
104+
105+
--- Update various bars & lines on Vim mode change.
106+
vim.api.nvim_create_autocmd({ "ModeChanged" }, {
107+
callback = function (event)
108+
---|fS
109+
110+
pcall(vim.api.nvim__redraw, {
111+
buf = event.buf,
112+
flush = true,
113+
114+
statuscolumn = true,
115+
statusline = true,
116+
winbar = true,
117+
tabline = true
118+
});
119+
120+
---|fE
78121
end
79122
});

0 commit comments

Comments
 (0)