@@ -58,6 +58,7 @@ qx.Class.define("osparc.ui.markdown.Markdown2", {
5858
5959 this . addListenerOnce ( "appear" , ( ) => {
6060 this . getContentElement ( ) . addClass ( "osparc-markdown" ) ;
61+ this . __scheduleResize ( ) ; // first paint sizing
6162 } ) ;
6263 } ,
6364
@@ -115,12 +116,32 @@ qx.Class.define("osparc.ui.markdown.Markdown2", {
115116
116117 this . setHtml ( safeHtml ) ;
117118
118- // for some reason the content is not immediately there
119+ /*
120+ // Wait for DOM update
119121 qx.event.Timer.once(() => {
120122 this.__resizeMe();
121- } , this , 100 ) ;
123+ }, this, 50);
124+ */
122125
123- this . __resizeMe ( ) ;
126+ /*
127+ // this.__resizeMe();
128+ this.getContentElement().addListenerOnce("appear", () => {
129+ this.__resizeMe();
130+ });
131+ */
132+
133+ // resize once DOM is updated/painted
134+ this . __scheduleResize ( ) ;
135+
136+ // also resize once images load (they change height later)
137+ const el = this . __getDomElement ( ) ;
138+ if ( el ) {
139+ el . querySelectorAll ( "img" ) . forEach ( img => {
140+ if ( ! img . complete ) {
141+ img . addEventListener ( "load" , ( ) => this . __scheduleResize ( ) , { once : true } ) ;
142+ }
143+ } ) ;
144+ }
124145 } ) . catch ( error => console . error ( error ) ) ;
125146 } ,
126147
@@ -135,14 +156,28 @@ qx.Class.define("osparc.ui.markdown.Markdown2", {
135156 return null ;
136157 } ,
137158
138- // qx.ui.embed.html scale to content
139- __resizeMe : function ( ) {
159+ __scheduleResize : function ( ) {
140160 const domElement = this . __getDomElement ( ) ;
141- if ( domElement === null ) {
161+ if ( ! domElement ) {
142162 return ;
143163 }
144- this . setHeight ( null ) ; // let it auto-size
145- this . setMinHeight ( domElement . scrollHeight ) ; // so layout respects full content
164+
165+ // collapse first so we don't re-measure an old minHeight
166+ this . setHeight ( null ) ;
167+ this . setMinHeight ( 0 ) ;
168+
169+ window . requestAnimationFrame ( ( ) => {
170+ // look inside the Html content element
171+ const inner = domElement . firstElementChild || domElement ;
172+ const rect = inner . getBoundingClientRect ( ) ;
173+ const contentH = Math . ceil ( rect ? rect . height : 0 ) ;
174+
175+ const insets = this . getInsets ? this . getInsets ( ) : { top : 0 , bottom : 0 } ;
176+ const totalH = Math . max ( 0 , contentH + ( insets . top || 0 ) + ( insets . bottom || 0 ) ) ;
177+
178+ this . setMinHeight ( totalH ) ;
179+ this . setHeight ( totalH ) ;
180+ } ) ;
146181 } ,
147182 }
148183} ) ;
0 commit comments