Skip to content

Commit

Permalink
Merge pull request #476 from processing/fix/reference-scroll
Browse files Browse the repository at this point in the history
Try to fit reference example canvas sizes better
  • Loading branch information
Qianqianye authored Jul 31, 2024
2 parents ea0c250 + cd331b1 commit 1547249
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/components/CodeEmbed/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ export const CodeEmbed = (props) => {
initialCode.replace(/\u00A0/g, " "),
);

let { previewWidth, previewHeight } = props;
const canvasMatch = /createCanvas\(\s*(\d+),\s*(\d+)\s*(?:,\s*(?:P2D|WEBGL)\s*)?\)/m.exec(initialCode);
if (canvasMatch) {
previewWidth = previewWidth || parseFloat(canvasMatch[1]);
previewHeight = previewHeight || parseFloat(canvasMatch[2]);
}

// Quick hack to make room for DOM that gets added below the canvas by default
const domMatch = /create(Button|Select|P|Div|Input)/.exec(initialCode);
if (domMatch && previewHeight) {
previewHeight += 100;
}

const codeFrameRef = useRef(null);

const updateOrReRun = () => {
Expand Down Expand Up @@ -70,8 +83,8 @@ export const CodeEmbed = (props) => {
<div>
<CodeFrame
jsCode={previewCodeString}
width={props.previewWidth}
height={props.previewHeight}
width={previewWidth}
height={previewHeight}
base={props.base}
frameRef={codeFrameRef}
lazyLoad={props.lazyLoad}
Expand Down
2 changes: 0 additions & 2 deletions src/layouts/ReferenceItemLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ const seenParams: Record<string, true> = {};
previewable={!classes.norender}
editable
lazyLoad={false}
previewHeight="100px"
previewWidth="100px"
allowSideBySide={true}
/>
);
Expand Down

0 comments on commit 1547249

Please sign in to comment.