@@ -22,10 +22,12 @@ import { ElementExt } from "@lumino/domutils";
22
22
import { IDisposable } from "@lumino/disposable" ;
23
23
24
24
import { crdebug } from "./cr-logger" ;
25
+ import { MessageLoop } from "@lumino/messaging" ;
25
26
26
27
export class CodeRibbonTheiaPatch extends TabPanel {
27
28
private _renderer ?: DockLayout . IRenderer ;
28
29
readonly tabBar : TabBar < Widget > ;
30
+ private _tabBarMutationObserver ?: MutationObserver ;
29
31
30
32
constructor ( options : CodeRibbonTheiaPatch . IOptions = { } ) {
31
33
super ( ) ;
@@ -74,6 +76,14 @@ export class CodeRibbonTheiaPatch extends TabPanel {
74
76
( this . layout as BoxLayout ) . insertWidget ( 0 , this . tabBar ) ;
75
77
// this.layout.addWidget(this.stackedPanel);
76
78
79
+ this . _tabBarMutationObserver = new MutationObserver (
80
+ ( ) => this . onTabBarMutated ,
81
+ ) ;
82
+ this . _tabBarMutationObserver . observe ( this . tabBar . node , {
83
+ childList : true ,
84
+ subtree : true ,
85
+ } ) ;
86
+
77
87
// crdebug("patch constructor done, made this", this, this.tabBar);
78
88
}
79
89
@@ -87,12 +97,54 @@ export class CodeRibbonTheiaPatch extends TabPanel {
87
97
// enable the TabBar to support dragging the tab out of the bar:
88
98
this . tabBar . tabsMovable = true ;
89
99
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
+ } ) ;
90
135
}
91
136
92
137
override activate ( ) : void {
93
138
super . activate ( ) ;
94
139
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 ( ) ;
96
148
}
97
149
98
150
get contentful_size ( ) : number {
0 commit comments