@@ -593,9 +593,19 @@ winbar.config = {
593593--- @type winbar.state
594594winbar .state = {
595595 enable = true ,
596- attached_windows = {}
596+
597+ attached_windows = {},
598+ win_state = {}
597599};
598600
601+ winbar .get_win_state = function (window )
602+ return winbar .state .attached_windows [window ]
603+ end
604+
605+ winbar .set_win_state = function (window , state )
606+ winbar .state .attached_windows [window ] = state ;
607+ end
608+
599609winbar .check_condition = function (buffer , window )
600610 if not winbar .config .condition then
601611 return true ;
@@ -656,8 +666,9 @@ winbar.start = function ()
656666
657667 vim .api .nvim_set_option_value (" winbar" , WBR , { scope = " global" })
658668
659- local win = vim .api .nvim_get_current_win ();
660- winbar .attach (win );
669+ for _ , win in ipairs (vim .api .nvim_list_wins ()) do
670+ winbar .attach (win );
671+ end
661672
662673 --- | fE
663674end
@@ -668,29 +679,25 @@ Attaches the custom `statusline` to **window**.
668679Set `ignore_enabled` to **true** to disable module state checker.
669680]]
670681--- @param window integer
671- --- @param ignore_enabled ? boolean
672- winbar .attach = function (window , ignore_enabled )
682+ winbar .attach = function (window )
673683 --- | fS
674684
675685 --[[ Forcefully attach to `window`? ]]
676686 --- @return boolean
677687 local function force_attach ()
678- if
679- winbar .config .force_attach and
680- vim .islist (winbar .config .force_attach ) and
681- vim .list_contains (winbar .config .force_attach , vim .wo [window ].statusline )
682- then
683- return true ;
684- end
685-
686- return false ;
688+ return vim .list_contains (
689+ winbar .config .force_attach or {},
690+ vim .wo [window ].winbar
691+ );
687692 end
688693
689- if winbar .state .attached_windows [window ] == true then
694+ local state = winbar .get_win_state (window );
695+ local current_winbar = vim .wo [window ].winbar ;
696+
697+ if state ~= nil then
690698 -- Do not attach if **already attached to a window**.
691699 return ;
692- elseif vim .wo [window ].winbar ~= WBR and vim .wo [window ].winbar ~= vim .g .__winbar and force_attach () ~= true then
693- -- Do not attach to windows with `custom winbar`.
700+ elseif current_winbar ~= WBR and current_winbar ~= " " and force_attach () == false then
694701 return ;
695702 end
696703
@@ -707,14 +714,11 @@ winbar.attach = function (window, ignore_enabled)
707714 -- Do not attach if **conditionally ignored**.
708715 winbar .detach (window );
709716 else
710- if ignore_enabled ~= true then
711- -- Do not attach if **this module is disabled**.
712- winbar .state .attached_windows [window ] = false ;
713- return ;
714- end
715-
716717 winbar .set (window );
717718 winbar .state .attached_windows [window ] = true ;
719+
720+ winbar .set_win_state (window , true );
721+
718722 end
719723
720724 --- | fE
@@ -730,15 +734,18 @@ NOTE: This will *reset* the statusline for that window.
730734winbar .detach = function (window , set_state )
731735 --- | fS
732736
733- if winbar .state .attached_windows [window ] == false then
734- -- Do not detach for unattached windows.
737+ local state = winbar .get_win_state (window );
738+ local current_winbar = vim .wo [window ].winbar ;
739+
740+ if state == nil or current_winbar ~= WBR then
741+ -- Not attached or changed winbar.
735742 return ;
736743 end
737744
738745 winbar .remove (window );
739746
740747 if set_state then
741- winbar .state . attached_windows [ window ] = false ;
748+ winbar .set_win_state ( window , false ) ;
742749 end
743750
744751 --- | fE
859866winbar .Enable = function ()
860867 --- | fS
861868
862- -- vim.print(winbar.state.attached_windows)
863869 for win , state in pairs (winbar .state .attached_windows ) do
864870 if state == false then
865871 winbar .enable (win );
891897winbar .toggle = function (window )
892898 --- | fS
893899
894- if winbar .state .attached_windows [window ] == true then
900+ local state = winbar .get_win_state (window );
901+
902+ if state == true then
895903 winbar .disable (window );
896- else
904+ elseif state == false then
897905 winbar .enable (window );
898906 end
899907
@@ -903,15 +911,15 @@ end
903911--[[ Enables `winbar` for `window`. ]]
904912--- @param window integer
905913winbar .enable = function (window )
914+ winbar .set_win_state (window , true );
906915 winbar .set (window );
907- winbar .state .attached_windows [window ] = true ;
908916end
909917
910918--[[ Disables `winbar` for `window`. ]]
911919--- @param window integer
912920winbar .disable = function (window )
921+ winbar .set_win_state (window , false );
913922 winbar .remove (window );
914- winbar .state .attached_windows [window ] = false ;
915923end
916924
917925---- --------------------------------------------------------------------------
0 commit comments