Skip to content

Commit 1547249

Browse files
authored
Merge pull request #476 from processing/fix/reference-scroll
Try to fit reference example canvas sizes better
2 parents ea0c250 + cd331b1 commit 1547249

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/components/CodeEmbed/index.jsx

+15-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ export const CodeEmbed = (props) => {
3434
initialCode.replace(/\u00A0/g, " "),
3535
);
3636

37+
let { previewWidth, previewHeight } = props;
38+
const canvasMatch = /createCanvas\(\s*(\d+),\s*(\d+)\s*(?:,\s*(?:P2D|WEBGL)\s*)?\)/m.exec(initialCode);
39+
if (canvasMatch) {
40+
previewWidth = previewWidth || parseFloat(canvasMatch[1]);
41+
previewHeight = previewHeight || parseFloat(canvasMatch[2]);
42+
}
43+
44+
// Quick hack to make room for DOM that gets added below the canvas by default
45+
const domMatch = /create(Button|Select|P|Div|Input)/.exec(initialCode);
46+
if (domMatch && previewHeight) {
47+
previewHeight += 100;
48+
}
49+
3750
const codeFrameRef = useRef(null);
3851

3952
const updateOrReRun = () => {
@@ -70,8 +83,8 @@ export const CodeEmbed = (props) => {
7083
<div>
7184
<CodeFrame
7285
jsCode={previewCodeString}
73-
width={props.previewWidth}
74-
height={props.previewHeight}
86+
width={previewWidth}
87+
height={previewHeight}
7588
base={props.base}
7689
frameRef={codeFrameRef}
7790
lazyLoad={props.lazyLoad}

src/layouts/ReferenceItemLayout.astro

-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ const seenParams: Record<string, true> = {};
104104
previewable={!classes.norender}
105105
editable
106106
lazyLoad={false}
107-
previewHeight="100px"
108-
previewWidth="100px"
109107
allowSideBySide={true}
110108
/>
111109
);

0 commit comments

Comments
 (0)