@@ -22,10 +22,12 @@ import { ElementExt } from "@lumino/domutils";
2222import { IDisposable } from "@lumino/disposable" ;
2323
2424import { crdebug } from "./cr-logger" ;
25+ import { MessageLoop } from "@lumino/messaging" ;
2526
2627export class CodeRibbonTheiaPatch extends TabPanel {
2728 private _renderer ?: DockLayout . IRenderer ;
2829 readonly tabBar : TabBar < Widget > ;
30+ private _tabBarMutationObserver ?: MutationObserver ;
2931
3032 constructor ( options : CodeRibbonTheiaPatch . IOptions = { } ) {
3133 super ( ) ;
@@ -74,6 +76,14 @@ export class CodeRibbonTheiaPatch extends TabPanel {
7476 ( this . layout as BoxLayout ) . insertWidget ( 0 , this . tabBar ) ;
7577 // this.layout.addWidget(this.stackedPanel);
7678
79+ this . _tabBarMutationObserver = new MutationObserver (
80+ ( ) => this . onTabBarMutated ,
81+ ) ;
82+ this . _tabBarMutationObserver . observe ( this . tabBar . node , {
83+ childList : true ,
84+ subtree : true ,
85+ } ) ;
86+
7787 // crdebug("patch constructor done, made this", this, this.tabBar);
7888 }
7989
@@ -87,12 +97,54 @@ export class CodeRibbonTheiaPatch extends TabPanel {
8797 // enable the TabBar to support dragging the tab out of the bar:
8898 this . tabBar . tabsMovable = true ;
8999 this . tabBar . allowDeselect = false ;
100+
101+ this . refitBoxLayout ( ) ;
102+ }
103+
104+ /**
105+ * TODO find the best place for this:
106+ * I am not sure at which stage or event Theia creates the breadcrumbs, but this should be triggered by that action
107+ *
108+ * we need to initiate another fit since theia adds breadcrumbs to the TabBar that TabPanel (using BoxLayout) doesn't account for in the constructor
109+ * this should be run upon any event which could cause the size of the TabBar to change,
110+ * I believe it's idempotent, but it would be an expensive operation to perform on every resize or across all patches
111+ *
112+ * we do it as a message instead of calling ._fit directly as it's private and could be overriden or caught in some other place
113+ */
114+ refitBoxLayout ( ) : void {
115+ MessageLoop . sendMessage ( this , Widget . Msg . FitRequest ) ;
116+ }
117+
118+ override dispose ( ) : void {
119+ super . dispose ( ) ;
120+ if ( this . _tabBarMutationObserver ) {
121+ this . _tabBarMutationObserver . disconnect ( ) ;
122+ }
123+ }
124+
125+ onTabBarMutated ( mutationList : MutationRecord [ ] , observer : MutationObserver ) {
126+ crdebug ( "patch: onTabBarMutated:" , this , mutationList , observer ) ;
127+ /**
128+ * we only care for direct descendants of the TabBar, because the breadcrumbs are added like:
129+ * .lm-TabBar > .theia-tabBar-breadcrumb-row
130+ */
131+ mutationList . forEach ( ( mut ) => {
132+ crdebug ( "patch: FitRequest because the TabBar nodes were changed" , this ) ;
133+ this . refitBoxLayout ( ) ;
134+ } ) ;
90135 }
91136
92137 override activate ( ) : void {
93138 super . activate ( ) ;
94139 crdebug ( "Patch activate" , this ) ;
95- if ( this . contentful_widget ) this . contentful_widget . activate ( ) ;
140+ if ( this . contentful_widget ) {
141+ this . contentful_widget . activate ( ) ;
142+ }
143+
144+ // TODO find a better place to trigger this
145+ // temporary HACK until I find a working solution to trigger it elsewhere
146+ // (this._tabBarMutationObserver does not seem to be working)
147+ this . refitBoxLayout ( ) ;
96148 }
97149
98150 get contentful_size ( ) : number {
0 commit comments