diff --git a/site/src/components/Repl/CodeMirror.svelte b/site/src/components/Repl/CodeMirror.svelte index 8c3f5a0660..e9519e516e 100644 --- a/site/src/components/Repl/CodeMirror.svelte +++ b/site/src/components/Repl/CodeMirror.svelte @@ -39,7 +39,9 @@ } code = new_code; + updating_externally = true; if (editor) editor.setValue(code); + updating_externally = false; } export function update(new_code) { @@ -56,6 +58,10 @@ editor.refresh(); } + export function focus() { + editor.focus(); + } + const modes = { js: { name: 'javascript', @@ -73,7 +79,7 @@ const refs = {}; let editor; - let updating = false; + let updating_externally = false; let marker; let error_line; let destroyed = false; @@ -131,10 +137,6 @@ } }); - beforeUpdate(() => { - updating = false; - }); - function createEditor(mode) { if (destroyed || !CodeMirror) return; @@ -163,10 +165,9 @@ editor = CodeMirror.fromTextArea(refs.editor, opts); editor.on('change', instance => { - if (!updating) { - updating = true; - // code = instance.getValue(); - dispatch('change', { value: instance.getValue() }); + if (!updating_externally) { + const value = instance.getValue(); + dispatch('change', { value }); } }); diff --git a/site/src/components/Repl/Input/ComponentSelector.svelte b/site/src/components/Repl/Input/ComponentSelector.svelte index 02511c373d..7933306b0a 100644 --- a/site/src/components/Repl/Input/ComponentSelector.svelte +++ b/site/src/components/Repl/Input/ComponentSelector.svelte @@ -5,7 +5,7 @@ export let handle_select; - const { components, selected } = getContext('REPL'); + const { components, selected, request_focus } = getContext('REPL'); let editing = null; @@ -28,7 +28,13 @@ if (match && match[2]) $selected.type = match[2]; editing = null; + // re-select, in case the type changed + handle_select($selected); + components = components; // TODO necessary? + + // focus the editor, but wait a beat (so key events aren't misdirected) + setTimeout(request_focus); } function remove(component) { @@ -43,7 +49,7 @@ console.error(`Could not find component! That's... odd`); } - selected.set($components[index] || $components[$components.length - 1]); + handle_select($components[index] || $components[$components.length - 1]); } } @@ -70,7 +76,7 @@ }); components.update(components => components.concat(component)); - selected.set(component); + handle_select(component); } @@ -83,7 +89,6 @@ .file-tabs { border: none; - padding: 0 0 0 5rem; margin: 0; white-space: nowrap; overflow-x: auto; @@ -91,16 +96,21 @@ height: 10em; } - .file-tabs button { + .file-tabs .button, .file-tabs button { position: relative; + display: inline-block; font: 400 1.2rem/1.5 var(--font); border-bottom: var(--border-w) solid transparent; - padding: 1.2rem 1.2rem 0.8rem 0.5rem; - margin: 0 0.5rem 0 0; + padding: 1.2rem 1.4rem 0.8rem 0.8rem; + margin: 0; color: #999; } - .file-tabs button.active { + .file-tabs .button:first-child { + padding-left: 1.2rem; + } + + .file-tabs .button.active { /* color: var(--second); */ color: #333; border-bottom: var(--border-w) solid var(--prime); @@ -119,26 +129,15 @@ input { position: absolute; width: 100%; - left: 0.5rem; + left: 0.8rem; top: 1.2rem; - /* padding: 0 0.4rem; */ - /* font-size: 1rem; */ font: 400 1.2rem/1.5 var(--font); border: none; color: var(--flash); outline: none; - line-height: 1; background-color: transparent; } - .editable { - /* margin-right: 2.4rem; */ - } - - .uneditable { - /* padding-left: 1.2rem; */ - } - .remove { position: absolute; display: none; @@ -155,74 +154,78 @@ color: var(--flash); } - .file-tabs button.active .editable { + .file-tabs .button.active .editable { cursor: text; } - .file-tabs button.active .remove { - display: inline-block; + .file-tabs .button.active .remove { + display: block; } .add-new { position: absolute; left: 0; top: 0; - width: 5rem; - height: 100%; + padding: 1.2rem 1rem 0.8rem 0 !important; + height: 4.2rem; text-align: center; background-color: white; } .add-new:hover { - color: var(--flash); + color: var(--flash) !important; }
-
- {#each $components as component} - - {/each} -
+
+ {/each} - + + + {/if} diff --git a/site/src/components/Repl/Input/ModuleEditor.svelte b/site/src/components/Repl/Input/ModuleEditor.svelte index 272066e84f..bf1716e373 100644 --- a/site/src/components/Repl/Input/ModuleEditor.svelte +++ b/site/src/components/Repl/Input/ModuleEditor.svelte @@ -11,6 +11,10 @@ onMount(() => { register_module_editor(editor); }); + + export function focus() { + editor.focus(); + }