Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Commit53748b7

Browse files
committed
[fix] reset focus after iframe reload
Fixes#150
1 parentdeebd40 commit53748b7

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
5252
let width= browser?window.innerWidth:1000;
5353
let selected_view=0;
54+
/**@type{import('monaco-editor').editor.IStandaloneCodeEditor | undefined}*/
55+
let editor_instance;
5456
5557
$: mobile=writable(false);
5658
$: $mobile= width<768;
@@ -293,13 +295,30 @@
293295
294296
/**@param{string}src*/
295297
functionset_iframe_src(src) {
296-
//removing the iframe from the document allows us to
298+
//Removing the iframe from the document allows us to
297299
// change the src without adding a history entry, which
298-
// would make back/forward traversal very annoying
300+
// would make back/forward traversal very annoying.
299301
constparentNode=/**@type{HTMLElement}*/ (iframe.parentNode);
300302
parentNode?.removeChild(iframe);
301303
iframe.src= src;
302304
parentNode?.appendChild(iframe);
305+
// We need to reset focus because it's lost on reload when the
306+
// inner app has `export const ssr = false`, which results in
307+
// a initial navigation with a focus reset at the end.
308+
consteditor_has_focus= editor_instance?.hasTextFocus();
309+
constactive_element=document.activeElement;
310+
conston_blur= ()=> {
311+
// Timeout so that following focus event happens first
312+
setTimeout(()=> {
313+
if (editor_has_focus) {
314+
editor_instance?.focus();
315+
}else {
316+
active_element?.focus();
317+
}
318+
});
319+
};
320+
document.addEventListener('focusout', on_blur, { once:true });
321+
setTimeout(()=>document.removeEventListener('focusout', on_blur),2000);
303322
}
304323
</script>
305324
@@ -391,6 +410,7 @@
391410
stubs={$files}
392411
selected={$selected}
393412
read_only={$mobile}
413+
bind:editor_instance
394414
on:change={update_stub}
395415
/>
396416
<ImageViewer selected={$selected}/>

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,20 @@
2424
/**@type{import('$lib/types').Stub | null}*/
2525
exportlet selected=null;
2626
exportlet read_only=false;
27+
/**@type{import('monaco-editor').editor.IStandaloneCodeEditor | undefined}*/
28+
exportlet editor_instance;
2729
2830
constdispatch=createEventDispatcher();
2931
3032
/**@type{HTMLDivElement}*/
3133
let container;
3234
33-
/**@type{ReturnType<typeof init> | undefined}*/
34-
let instance;
35-
3635
let w=0;
3736
let h=0;
3837
38+
/**@type{ReturnType<typeof init> | undefined}*/
39+
let instance;
40+
3941
onMount(()=> {
4042
let destroyed=false;
4143
@@ -50,6 +52,7 @@
5052
import('$lib/client/monaco/monaco.js').then(({ monaco })=> {
5153
if (destroyed)return;
5254
instance=init(monaco, dark_mode);
55+
editor_instance=instance.editor;
5356
});
5457
5558
/**@param{MediaQueryListEvent}event*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp