Skip to content

Commit feedc3c

Browse files
committed
Editor: refocus CM on blur from Tab
1 parent 4695254 commit feedc3c

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

editor/index.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,20 @@
181181

182182
// Load default sketch on page load using inline JS blob
183183
window.addEventListener('load', () => {
184-
// Prevent Tab from leaving CodeMirror in Firefox
185184
setTimeout(() => {
186-
document.querySelectorAll('a, button, input, select, textarea, [tabindex]').forEach(el => {
185+
document.querySelectorAll('a, button, input, select, [tabindex]').forEach(el => {
187186
if (!el.closest('.CodeMirror')) el.setAttribute('tabindex', '-1');
188187
});
189-
}, 200);
188+
// Refocus CM textarea if it loses focus to Tab
189+
const ta = document.querySelector('.CodeMirror textarea');
190+
if (ta) {
191+
ta.addEventListener('blur', e => {
192+
if (e.relatedTarget && !e.relatedTarget.closest('.CodeMirror')) {
193+
setTimeout(() => ta.focus(), 0);
194+
}
195+
});
196+
}
197+
}, 300);
190198
const jsBlob = URL.createObjectURL(new Blob([DEFAULT_JS], {type:'application/javascript'}));
191199
// We need the data file -- fetch it
192200
Promise.all([

0 commit comments

Comments
 (0)