Skip to content

Commit

Permalink
fix: creating a new object or array by typing { or ] broken (regr…
Browse files Browse the repository at this point in the history
…ession since `v0.14.1`)
  • Loading branch information
josdejong committed Jan 27, 2023
1 parent 2a306be commit f7b5f92
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/lib/logic/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ export interface OnInsert {
insertType: InsertType
selectInside: boolean
refJsonEditor: HTMLElement
json: JSONValue
json: JSONValue | undefined
documentState: DocumentState
readOnly: boolean
parser: JSONParser
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/lib/logic/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ export function moveInsideParent(
}

export function createNewValue(
json: JSONValue,
json: JSONValue | undefined,
selection: JSONSelection | undefined,
valueType: 'object' | 'array' | 'structure' | 'value'
) {
Expand All @@ -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)

Expand Down

0 comments on commit f7b5f92

Please sign in to comment.