Skip to content

Commit d9992ab

Browse files
committed
Editor: auto-run spinning cube on load, fix backspace, add DEFAULT sketch
1 parent fe135cb commit d9992ab

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

editor/index.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,23 @@
136136
<script>
137137
const API = 'https://bench-volumes-pontiac-riders.trycloudflare.com';
138138

139+
const DEFAULT = `float angle = 0;
140+
141+
void setup() {
142+
size(500, 400, P3D);
143+
}
144+
145+
void draw() {
146+
background(20);
147+
lights();
148+
translate(width/2, height/2);
149+
rotateX(angle * 0.7f);
150+
rotateY(angle);
151+
fill(232, 180, 0);
152+
box(130);
153+
angle += 0.02f;
154+
}`;
155+
139156
const editor = CodeMirror.fromTextArea(document.getElementById('code'), {
140157
mode: 'cppmode',
141158
theme: 'cppmode',
@@ -256,6 +273,15 @@
256273
document.head.appendChild(script);
257274
}
258275

276+
const _origPreventDefault = Event.prototype.preventDefault;
277+
Event.prototype.preventDefault = function() {
278+
if (this.type === 'keydown' || this.type === 'keyup' || this.type === 'keypress') {
279+
const ta = document.querySelector('.CodeMirror textarea');
280+
if (ta && document.activeElement === ta) return;
281+
}
282+
return _origPreventDefault.call(this);
283+
};
284+
259285
document.addEventListener('keydown', e => {
260286
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') { e.preventDefault(); runSketch(); }
261287
});

0 commit comments

Comments
 (0)