Skip to content

Commit d45c551

Browse files
committed
height working
1 parent 74e8972 commit d45c551

File tree

1 file changed

+17
-11
lines changed
  • services/static-webserver/client/source/class/osparc/ui/markdown

1 file changed

+17
-11
lines changed

services/static-webserver/client/source/class/osparc/ui/markdown/Markdown2.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +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
61+
this.__scheduleResize(); // first paint sizing
6262
});
6363
},
6464

@@ -70,17 +70,16 @@ qx.Class.define("osparc.ui.markdown.Markdown2", {
7070
check: "String",
7171
apply: "__applyMarkdown"
7272
},
73-
74-
noMargin: {
75-
check: "Boolean",
76-
init: false
77-
}
7873
},
7974

8075
events: {
8176
"resized": "qx.event.type.Event",
8277
},
8378

79+
statics: {
80+
WRAP_CLASS: "osparc-md-root"
81+
},
82+
8483
members: {
8584
__loadMarked: null,
8685

@@ -115,7 +114,8 @@ qx.Class.define("osparc.ui.markdown.Markdown2", {
115114

116115
const safeHtml = osparc.wrapper.DOMPurify.getInstance().sanitize(html);
117116

118-
this.setHtml(safeHtml);
117+
// flow-root prevents margin collapsing; inline style avoids extra stylesheet juggling
118+
this.setHtml(`<div class="${this.self().WRAP_CLASS}" style="display:flow-root;">${safeHtml}</div>`);
119119

120120
// resize once DOM is updated/painted
121121
this.__scheduleResize();
@@ -154,17 +154,23 @@ qx.Class.define("osparc.ui.markdown.Markdown2", {
154154
this.setMinHeight(0);
155155

156156
window.requestAnimationFrame(() => {
157-
// look inside the Html content element
158-
const inner = domElement.firstElementChild || domElement;
157+
// force reflow
158+
void domElement.offsetHeight;
159+
160+
// measure the wrapper we injected (covers ALL children)
161+
const inner = domElement.querySelector("."+this.self().WRAP_CLASS) || domElement;
159162
const rect = inner.getBoundingClientRect();
160163
const contentH = Math.ceil(rect ? rect.height : 0);
161164

162-
const insets = this.getInsets ? this.getInsets() : {top: 0, bottom: 0};
165+
// include widget insets (decorator/padding/border)
166+
const insets = this.getInsets ? this.getInsets() : { top: 0, bottom: 0 };
163167
const totalH = Math.max(0, contentH + (insets.top || 0) + (insets.bottom || 0));
164168

165169
this.setMinHeight(totalH);
166170
this.setHeight(totalH);
167-
console.log("Markdown2 resized to height", totalH);
171+
console.log("totalH", totalH);
172+
173+
this.fireEvent("resized");
168174
});
169175
},
170176
}

0 commit comments

Comments
 (0)