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.

regain focus when it gets lost by mistake#161

Merged
dummdidumm merged 3 commits intomainfromgh-150
Dec 16, 2022
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletionssrc/routes/tutorial/[slug]/Editor.svelte
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
<script>
import { dev } from '$app/environment';
import { monaco } from '$lib/client/monaco/monaco.js';
import { createEventDispatcher, onMount } from 'svelte';

/**
Expand DownExpand Up@@ -36,6 +35,13 @@
let w = 0;
let h = 0;

/**
* The iframe sometimes takes focus control in ways we can't prevent
* while the editor is focussed. Refocus the editor in these cases.
* This boolean tracks whether or not the editor should be refocused.
*/
let preserve_focus = true;

onMount(() => {
let destroyed = false;

Expand DownExpand Up@@ -234,8 +240,37 @@
}
</script>

<svelte:window
on:pointerdown={(e) => {
if (!container.contains(/** @type {HTMLElement} */ (e.target))) {
preserve_focus = false;
}
}}
/>

<div bind:clientWidth={w} bind:clientHeight={h}>
<div bind:this={container} />
<div
bind:this={container}
on:keydown={(e) => {
if (e.key === 'Tab') {
preserve_focus = false;

setTimeout(() => {
preserve_focus = true;
}, 0);
}
}}
on:focusin={() => {
preserve_focus = true;
}}
on:focusout={() => {
if (preserve_focus) {
setTimeout(() => {
instance?.editor.focus();
}, 0);
}
}}
/>
</div>

<style>
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp