Skip to content

Commit 00892b4

Browse files
authored
1 parent 46dda23 commit 00892b4

File tree

4 files changed

+35
-49
lines changed

4 files changed

+35
-49
lines changed

content/tutorial/common/src/__client.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ window.addEventListener('message', async (e) => {
6363
}
6464
});
6565

66+
window.addEventListener('pointerdown', () => {
67+
parent.postMessage(
68+
{
69+
type: 'pointerdown'
70+
},
71+
'*'
72+
);
73+
});
74+
6675
function ping() {
6776
parent.postMessage(
6877
{
@@ -89,18 +98,3 @@ if (import.meta.hot) {
8998
);
9099
});
91100
}
92-
93-
/**
94-
* The iframe sometimes takes focus control in ways we can't prevent
95-
* while the editor is focussed. Refocus the editor in these cases.
96-
*/
97-
window.addEventListener('focusin', (e) => {
98-
if (e.target.tagName === 'BODY') {
99-
parent.postMessage(
100-
{
101-
type: 'focus_on_editor'
102-
},
103-
'*'
104-
);
105-
}
106-
});

src/routes/tutorial/[slug]/+page.svelte

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import ImageViewer from './ImageViewer.svelte';
1212
import ScreenToggle from './ScreenToggle.svelte';
1313
import Sidebar from './Sidebar.svelte';
14-
import { state, selected, completed } from './state';
14+
import { state, selected, completed } from './state.js';
1515
1616
/** @type {import('./$types').PageData} */
1717
export let data;
@@ -160,20 +160,6 @@
160160
flex-direction: column;
161161
}
162162
163-
iframe {
164-
width: 100%;
165-
height: 100%;
166-
flex: 1;
167-
resize: none;
168-
box-sizing: border-box;
169-
border: none;
170-
background: var(--sk-back-2);
171-
}
172-
173-
iframe:not(.loaded) {
174-
display: none;
175-
}
176-
177163
.editor-container {
178164
position: relative;
179165
background-color: var(--sk-back-3);

src/routes/tutorial/[slug]/Editor.svelte

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,7 @@
3030
let w = 0;
3131
let h = 0;
3232
33-
/**
34-
* The iframe sometimes takes focus control in ways we can't prevent
35-
* while the editor is focussed. Refocus the editor in these cases.
36-
* This boolean tracks whether or not the editor should be refocused.
37-
*/
38-
let preserve_focus = true;
39-
/** @type {any} */
40-
let remove_focus_timeout;
33+
let preserve_editor_focus = false;
4134
4235
onMount(() => {
4336
let destroyed = false;
@@ -238,27 +231,40 @@
238231
</script>
239232
240233
<svelte:window
234+
on:pointerdown={(e) => {
235+
console.log(`pointerdown ${container.contains(e.target)}`);
236+
if (!container.contains(/** @type {HTMLElement} */ (e.target))) {
237+
preserve_editor_focus = false;
238+
}
239+
}}
241240
on:message={(e) => {
242-
if (preserve_focus && e.data.type === 'focus_on_editor') {
243-
instance?.editor.focus();
241+
if (e.data.type === 'pointerdown') {
242+
preserve_editor_focus = false;
244243
}
245244
}}
246245
/>
247246
248247
<div bind:clientWidth={w} bind:clientHeight={h}>
249248
<div
250249
bind:this={container}
250+
on:keydown={(e) => {
251+
if (e.key === 'Tab') {
252+
preserve_editor_focus = false;
253+
254+
setTimeout(() => {
255+
preserve_editor_focus = true;
256+
}, 100);
257+
}
258+
}}
251259
on:focusin={() => {
252-
clearTimeout(remove_focus_timeout);
253-
preserve_focus = true;
260+
preserve_editor_focus = true;
254261
}}
255262
on:focusout={() => {
256-
// Heuristic: user did refocus themmselves if focus_on_editor
257-
// doesn't happen in the next few miliseconds. Needed
258-
// because else navigations inside the iframe refocus the editor.
259-
remove_focus_timeout = setTimeout(() => {
260-
preserve_focus = false;
261-
}, 500);
263+
if (preserve_editor_focus) {
264+
setTimeout(() => {
265+
instance?.editor.focus();
266+
}, 0);
267+
}
262268
}}
263269
/>
264270
</div>

src/routes/tutorial/[slug]/Output.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import Chrome from './Chrome.svelte';
66
import Loading from './Loading.svelte';
77
import { create_adapter } from './adapter';
8-
import { state } from './state';
8+
import { state } from './state.js';
99
1010
/** @type {string} */
1111
export let path;

0 commit comments

Comments
 (0)