Skip to content

Commit

Permalink
fix code preview height change not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Kim committed Feb 29, 2024
1 parent ad2f083 commit cbec13b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
3 changes: 0 additions & 3 deletions website/src/components/code-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ export function* CodeEditor(

value = ev.target.value;
renderSource = "refresh";
currentEdit = ev.detail.edit;
this.refresh();
});

Expand All @@ -182,7 +181,6 @@ export function* CodeEditor(
selectionRange = selectionRangeFromEdit(edit);
keyer.transform(edit);
renderSource = "history";
currentEdit = edit;
this.refresh();
return true;
}
Expand All @@ -197,7 +195,6 @@ export function* CodeEditor(
selectionRange = selectionRangeFromEdit(edit);
keyer.transform(edit);
renderSource = "history";
currentEdit = edit;
this.refresh();
return true;
}
Expand Down
15 changes: 7 additions & 8 deletions website/src/components/code-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function generateIFrameHTML(
/>
</head>
<body>
<!-- TODO: extract these scripts to a separate file or something -->
<script>
const colorScheme = sessionStorage.getItem("color-scheme") ||
(
Expand All @@ -35,7 +36,6 @@ function generateIFrameHTML(
}
</script>
<script>
{
window.addEventListener("load", (ev) => {
window.parent.postMessage(
JSON.stringify({type: "executed", id: ${id}}),
Expand Down Expand Up @@ -66,9 +66,11 @@ function generateIFrameHTML(
});
const obs = new ResizeObserver((entries) => {
const height = entries[0].contentRect.height;
// has vertical scrollbar
if (window.innerWidth > document.documentElement.clientWidth) {
const height = Math.max(entries[0].contentRect.height, 100);
if (
document.documentElement.clientHeight <
document.documentElement.scrollHeight
) {
window.parent.postMessage(
JSON.stringify({
type: "resize",
Expand All @@ -80,10 +82,7 @@ function generateIFrameHTML(
}
})
setTimeout(() => {
obs.observe(document.documentElement);
}, 0);
}
obs.observe(document.documentElement);
</script>
<script type="module">${code}</script>
</body>
Expand Down
1 change: 1 addition & 0 deletions website/src/components/inline-code-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export function* InlineCodeBlock(
width: 100%;
border: 1px solid var(--text-color);
margin-top: -1px;
margin-right: -1px;
${editable
? `@media (min-width: ${breakpoint}) {
max-width: 61.8%;
Expand Down

0 comments on commit cbec13b

Please sign in to comment.