File tree Expand file tree Collapse file tree 1 file changed +37
-2
lines changed
src/routes/tutorial/[slug] Expand file tree Collapse file tree 1 file changed +37
-2
lines changed Original file line number Diff line number Diff line change 1
1
<script >
2
2
import { dev } from ' $app/environment' ;
3
- import { monaco } from ' $lib/client/monaco/monaco.js' ;
4
3
import { createEventDispatcher , onMount } from ' svelte' ;
5
4
6
5
/**
36
35
let w = 0 ;
37
36
let h = 0 ;
38
37
38
+ /**
39
+ * The iframe sometimes takes focus control in ways we can't prevent
40
+ * while the editor is focussed. Refocus the editor in these cases.
41
+ * This boolean tracks whether or not the editor should be refocused.
42
+ */
43
+ let preserve_focus = true ;
44
+
39
45
onMount (() => {
40
46
let destroyed = false ;
41
47
234
240
}
235
241
< / script>
236
242
243
+ < svelte: window
244
+ on: pointerdown= {(e ) => {
245
+ if (! container .contains (/** @type {HTMLElement} */ (e .target ))) {
246
+ preserve_focus = false ;
247
+ }
248
+ }}
249
+ / >
250
+
237
251
< div bind: clientWidth= {w} bind: clientHeight= {h}>
238
- < div bind: this = {container} / >
252
+ < div
253
+ bind: this = {container}
254
+ on: keydown= {(e ) => {
255
+ if (e .key === ' Tab' ) {
256
+ preserve_focus = false ;
257
+
258
+ setTimeout (() => {
259
+ preserve_focus = true ;
260
+ }, 0 );
261
+ }
262
+ }}
263
+ on: focusin= {() => {
264
+ preserve_focus = true ;
265
+ }}
266
+ on: focusout= {() => {
267
+ if (preserve_focus) {
268
+ setTimeout (() => {
269
+ instance? .editor .focus ();
270
+ }, 0 );
271
+ }
272
+ }}
273
+ / >
239
274
< / div>
240
275
241
276
< style>
You can’t perform that action at this time.
0 commit comments