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.

Commit24a31d2

Browse files
committed
revert#168,fix#167
1 parent450199e commit24a31d2

File tree

4 files changed

+43
-35
lines changed

4 files changed

+43
-35
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
functionping(){
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
importLoadingfrom'./Loading.svelte';
1414
importScreenTogglefrom'./ScreenToggle.svelte';
1515
importFiletreefrom'$lib/components/filetree/Filetree.svelte';
16+
import {set_preserve_editor_focus }from'./state';
1617
1718
/**@type{import('./$types').PageData}*/
1819
exportlet data;
@@ -292,6 +293,8 @@
292293
},1000);
293294
}elseif (e.data.type==='ping-pause') {
294295
clearTimeout(timeout);
296+
}elseif (e.data.type==='pointerdown') {
297+
set_preserve_editor_focus(false);
295298
}
296299
}
297300

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script>
22
import {dev }from'$app/environment';
33
import {createEventDispatcher,onMount }from'svelte';
4+
import {set_preserve_editor_focus,preserve_editor_focus }from'./state';
45
56
/**
67
* file extension -> monaco language
@@ -35,15 +36,6 @@
3536
let w=0;
3637
let h=0;
3738
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-
/**@type{any}*/
45-
let remove_focus_timeout;
46-
4739
onMount(()=> {
4840
let destroyed=false;
4941
@@ -243,27 +235,35 @@
243235
</script>
244236
245237
<svelte:window
246-
on:message={(e)=> {
247-
if (preserve_focus&&e.data.type==='focus_on_editor') {
248-
instance?.editor.focus();
238+
on:pointerdown={(e)=> {
239+
console.log(`pointerdown${container.contains(e.target)}`);
240+
if (!container.contains(/**@type{HTMLElement}*/ (e.target))) {
241+
set_preserve_editor_focus(false);
249242
}
250243
}}
251244
/>
252245
253246
<div bind:clientWidth={w} bind:clientHeight={h}>
254247
<div
255248
bind:this={container}
249+
on:keydown={(e)=> {
250+
if (e.key==='Tab') {
251+
set_preserve_editor_focus(false);
252+
253+
setTimeout(()=> {
254+
set_preserve_editor_focus(true);
255+
},100);
256+
}
257+
}}
256258
on:focusin={()=> {
257-
clearTimeout(remove_focus_timeout);
258-
preserve_focus=true;
259+
set_preserve_editor_focus(true);
259260
}}
260261
on:focusout={()=> {
261-
// Heuristic: user did refocus themmselves if focus_on_editor
262-
// doesn't happen in the next few miliseconds. Needed
263-
// because else navigations inside the iframe refocus the editor.
264-
remove_focus_timeout=setTimeout(()=> {
265-
preserve_focus=false;
266-
},500)
262+
if (preserve_editor_focus) {
263+
setTimeout(()=> {
264+
instance?.editor.focus();
265+
},0);
266+
}
267267
}}
268268
/>
269269
</div>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* The iframe sometimes takes focus control in ways we can't prevent
3+
* while the editor is focused. Refocus the editor in these cases.
4+
* This boolean tracks whether or not the editor should be refocused.
5+
*/
6+
exportletpreserve_editor_focus=false;
7+
8+
/**@param {boolean} value */
9+
exportfunctionset_preserve_editor_focus(value){
10+
preserve_editor_focus=value;
11+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp