From f7b5f925d7ae64aadad34007b82abc239127f537 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Fri, 27 Jan 2023 10:53:18 +0100 Subject: [PATCH] fix: creating a new object or array by typing `{` or `]` broken (regression since `v0.14.1`) --- src/lib/logic/actions.ts | 8 ++++---- src/lib/logic/operations.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/logic/actions.ts b/src/lib/logic/actions.ts index d9e41d11..1d016a43 100644 --- a/src/lib/logic/actions.ts +++ b/src/lib/logic/actions.ts @@ -479,7 +479,7 @@ export interface OnInsert { insertType: InsertType selectInside: boolean refJsonEditor: HTMLElement - json: JSONValue + json: JSONValue | undefined documentState: DocumentState readOnly: boolean parser: JSONParser @@ -601,7 +601,7 @@ export async function onInsertCharacter({ }: OnInsertCharacter) { // a regular key like a, A, _, etc is entered. // Replace selected contents with a new value having this first character as text - if (readOnly || !documentState.selection || !json) { + if (readOnly || !documentState.selection) { return } @@ -640,7 +640,7 @@ export async function onInsertCharacter({ onReplaceJson }) } else { - if (isValueSelection(documentState.selection)) { + if (isValueSelection(documentState.selection) && json !== undefined) { if (!isObjectOrArray(getIn(json, documentState.selection.focusPath))) { // only replace contents when not yet in edit mode (can happen when entering // multiple characters very quickly after each other due to the async handling) @@ -672,7 +672,7 @@ export async function onInsertCharacter({ interface OnInsertValueWithCharacter { char: string refJsonEditor: HTMLElement - json: JSONValue + json: JSONValue | undefined documentState: DocumentState readOnly: boolean parser: JSONParser diff --git a/src/lib/logic/operations.ts b/src/lib/logic/operations.ts index 0b149991..6f1ad768 100644 --- a/src/lib/logic/operations.ts +++ b/src/lib/logic/operations.ts @@ -534,7 +534,7 @@ export function moveInsideParent( } export function createNewValue( - json: JSONValue, + json: JSONValue | undefined, selection: JSONSelection | undefined, valueType: 'object' | 'array' | 'structure' | 'value' ) { @@ -546,7 +546,7 @@ export function createNewValue( return [] } - if (valueType === 'structure') { + if (valueType === 'structure' && json !== undefined) { const parentPath = selection ? getParentPath(selection) : [] const parent = getIn(json, parentPath)