From 9daeb9d19c5414b633927d4d51e8f8e5ae336dfc Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 16 Dec 2022 10:58:50 -0500 Subject: [PATCH 1/3] regain focus when it gets lost by mistake - closes #150 --- src/routes/tutorial/[slug]/Editor.svelte | 34 ++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/routes/tutorial/[slug]/Editor.svelte b/src/routes/tutorial/[slug]/Editor.svelte index 5833a7d15..c81a3197e 100644 --- a/src/routes/tutorial/[slug]/Editor.svelte +++ b/src/routes/tutorial/[slug]/Editor.svelte @@ -1,6 +1,5 @@ + { + if (!container.contains(/** @type {HTMLElement} */ (e.target))) { + preserve_focus = false; + } + }} +/> +
-
+
{ + if (e.key === 'Tab') { + preserve_focus = false; + + setTimeout(() => { + preserve_focus = true; + }); + } + }} + on:focusin={() => { + preserve_focus = true; + }} + on:focusout={() => { + if (preserve_focus) { + setTimeout(() => { + instance?.editor.focus(); + }, 0); + } + }} + />