From 2dc62f04056ec352fe548323dda5819e423a25d5 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Fri, 19 Jan 2024 15:04:27 +0100 Subject: [PATCH] fix: #381 method `set()` sometimes throwing an error in `text` mode --- src/lib/components/JSONEditor.svelte | 2 -- src/lib/components/modes/textmode/TextMode.svelte | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lib/components/JSONEditor.svelte b/src/lib/components/JSONEditor.svelte index ee9b9cdb..7a6be56f 100644 --- a/src/lib/components/JSONEditor.svelte +++ b/src/lib/components/JSONEditor.svelte @@ -159,8 +159,6 @@ // new editor id -> will re-create the editor instanceId = uniqueId() - await tick() // await re-render (creating the new editor) - // update content *after* re-render, so that the new editor will trigger an onChange event content = newContent } diff --git a/src/lib/components/modes/textmode/TextMode.svelte b/src/lib/components/modes/textmode/TextMode.svelte index 82ab596b..3ebad394 100644 --- a/src/lib/components/modes/textmode/TextMode.svelte +++ b/src/lib/components/modes/textmode/TextMode.svelte @@ -675,8 +675,6 @@ const newText = getText(newContent, indentation, parser) const isChanged = !isEqual(newContent, content) const previousContent = content - content = newContent - text = newText debug('setCodeMirrorContent', { isChanged, forceUpdate }) @@ -684,6 +682,9 @@ return } + content = newContent + text = newText + if (!disableTextEditor(text, acceptTooLarge)) { // keep state // to reset state: codeMirrorView.setState(EditorState.create({doc: text, extensions: ...}))