Skip to content

Commit

Permalink
fix: when switching to a different JSON parser, stringify and parse t…
Browse files Browse the repository at this point in the history
…he contents again
  • Loading branch information
josdejong committed Nov 4, 2022
1 parent 50ce3f0 commit 2cece4e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/lib/components/JSONEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
import Modal from 'svelte-simple-modal'
import { SORT_MODAL_OPTIONS, TRANSFORM_MODAL_OPTIONS } from '../constants.js'
import { uniqueId } from '../utils/uniqueId.js'
import { isEqualParser, isTextContent, validateContentType } from '../utils/jsonUtils'
import {
isEqualParser,
isJSONContent,
isTextContent,
validateContentType
} from '../utils/jsonUtils'
import AbsolutePopup from './modals/popup/AbsolutePopup.svelte'
import TextMode from './modes/textmode/TextMode.svelte'
import TreeMode from './modes/treemode/TreeMode.svelte'
Expand Down Expand Up @@ -107,6 +112,13 @@
$: {
if (!isEqualParser(parser, previousParser)) {
debug('parser changed, recreate editor')
if (isJSONContent(content)) {
content = {
json: parser.parse(previousParser.stringify(content.json))
}
}
previousParser = parser
// new editor id -> will re-create the editor
Expand Down

0 comments on commit 2cece4e

Please sign in to comment.