Skip to content

Commit

Permalink
fix: code mode throwing an exception when trying to validate an empty…
Browse files Browse the repository at this point in the history
… document
  • Loading branch information
josdejong committed Sep 11, 2021
1 parent 6b810b7 commit 412172b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/lib/components/modes/codemode/CodeMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import createDebug from 'debug'
import { immutableJSONPatch, revertJSONPatch } from 'immutable-json-patch'
import jsonrepair from 'jsonrepair'
import { debounce, isEmpty, uniqueId } from 'lodash-es'
import { debounce, uniqueId } from 'lodash-es'
import { getContext, onDestroy, onMount } from 'svelte'
import {
CHECK_VALID_JSON_DELAY,
Expand Down Expand Up @@ -412,14 +412,18 @@
// replace ace setAnnotations with custom function that also covers jsoneditor annotations
const originalSetAnnotations = aceSession.setAnnotations
aceSession.setAnnotations = function (annotations) {
const newAnnotations =
annotations && annotations.length
? annotations
: validationErrorsList.map(validationErrorToAnnotation)
if (text !== '') {
const newAnnotations =
annotations && annotations.length
? annotations
: validationErrorsList.map(validationErrorToAnnotation)
debug('setAnnotations', { annotations, newAnnotations })
debug('setAnnotations', { annotations, newAnnotations })
originalSetAnnotations.call(this, newAnnotations)
originalSetAnnotations.call(this, newAnnotations)
} else {
originalSetAnnotations.call(this, [])
}
}
// register onchange event
Expand Down

0 comments on commit 412172b

Please sign in to comment.