From e8c814f4f36ca15dc50004ca2927edd5723312c2 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Fri, 1 Nov 2024 15:06:38 +0100 Subject: [PATCH] fix: #498 pressing enter when editing a value submits form --- .../components/controls/EditableDiv.svelte | 4 + .../NavigationBarPathEditor.svelte | 3 + .../modes/tablemode/TableMode.svelte | 2 + .../components/modes/treemode/TreeMode.svelte | 1 + .../components/EditableValueInput.svelte | 2 + src/routes/development/+page.svelte | 127 ++++++++++-------- 6 files changed, 81 insertions(+), 58 deletions(-) diff --git a/src/lib/components/controls/EditableDiv.svelte b/src/lib/components/controls/EditableDiv.svelte index c8e7a84a..cb9da99c 100644 --- a/src/lib/components/controls/EditableDiv.svelte +++ b/src/lib/components/controls/EditableDiv.svelte @@ -86,11 +86,15 @@ const combo = keyComboFromEvent(event) if (combo === 'Escape') { + event.preventDefault() + handleCancel() } if (combo === 'Enter' || combo === 'Tab') { // apply changes + event.preventDefault() + closed = true const newValue = getDomValue() diff --git a/src/lib/components/controls/navigationBar/NavigationBarPathEditor.svelte b/src/lib/components/controls/navigationBar/NavigationBarPathEditor.svelte index 7d0fd589..c1568383 100644 --- a/src/lib/components/controls/navigationBar/NavigationBarPathEditor.svelte +++ b/src/lib/components/controls/navigationBar/NavigationBarPathEditor.svelte @@ -72,10 +72,13 @@ const combo = keyComboFromEvent(event) if (combo === 'Escape') { + event.preventDefault() onClose() } if (combo === 'Enter') { + event.preventDefault() + validationActive = true const result = parseAndValidate(inputPath) if (result.path !== undefined) { diff --git a/src/lib/components/modes/tablemode/TableMode.svelte b/src/lib/components/modes/tablemode/TableMode.svelte index 7e388c3c..d1e14ebf 100644 --- a/src/lib/components/modes/tablemode/TableMode.svelte +++ b/src/lib/components/modes/tablemode/TableMode.svelte @@ -1307,6 +1307,8 @@ } if (combo === 'Ctrl+Enter' && isValueSelection(selection)) { + event.preventDefault() + const value = getIn(json, selection.path) if (isUrl(value)) { diff --git a/src/lib/components/modes/treemode/TreeMode.svelte b/src/lib/components/modes/treemode/TreeMode.svelte index 863d2049..ba3d5c2c 100644 --- a/src/lib/components/modes/treemode/TreeMode.svelte +++ b/src/lib/components/modes/treemode/TreeMode.svelte @@ -1504,6 +1504,7 @@ const parent = getIn(json, initial(path)) if (Array.isArray(parent)) { // change into selection of the value + event.preventDefault() selection = createValueSelection(path) } } diff --git a/src/routes/components/EditableValueInput.svelte b/src/routes/components/EditableValueInput.svelte index f1d6ee1c..ec9ced4d 100644 --- a/src/routes/components/EditableValueInput.svelte +++ b/src/routes/components/EditableValueInput.svelte @@ -77,10 +77,12 @@ event.stopPropagation() if (event.key === 'Enter') { + event.preventDefault() apply() } if (event.key === 'Escape') { + event.preventDefault() cancel() } } diff --git a/src/routes/development/+page.svelte b/src/routes/development/+page.svelte index 520c37be..e367ab9c 100644 --- a/src/routes/development/+page.svelte +++ b/src/routes/development/+page.svelte @@ -726,35 +726,37 @@

{#if $showTreeEditor} - console.log('onFocus tree')} - onBlur={() => console.log('onBlur tree', { content: refTreeEditor?.get() })} - /> +
+ console.log('onFocus tree')} + onBlur={() => console.log('onBlur tree', { content: refTreeEditor?.get() })} + /> + {/if}
@@ -787,35 +789,37 @@
{#if $showTextEditor} - console.log('onFocus text')} - onBlur={() => console.log('onBlur text', { content: refTextEditor?.get() })} - /> +
+ console.log('onFocus text')} + onBlur={() => console.log('onBlur text', { content: refTextEditor?.get() })} + /> + {/if}
@@ -933,8 +937,15 @@ See https://github.com/sveltejs/kit/issues/981 min-width: 0; } + form { + flex: 1; + display: flex; + } + .tree-editor, .text-editor { + display: flex; + // some styling to try out if it doesn't break the styling of the editor line-height: 72px; font-size: 72px;