From 12583bad320ac241a8e55cb2575d7c28536f5e76 Mon Sep 17 00:00:00 2001 From: Danilo Woznica Date: Thu, 20 Jan 2022 10:32:39 +0000 Subject: [PATCH] fix(codemirror): shift approach to remove placeholder --- .../src/components/CodeEditor/CodeMirror.tsx | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/sandpack-react/src/components/CodeEditor/CodeMirror.tsx b/sandpack-react/src/components/CodeEditor/CodeMirror.tsx index 480ef4073..643c05b3e 100644 --- a/sandpack-react/src/components/CodeEditor/CodeMirror.tsx +++ b/sandpack-react/src/components/CodeEditor/CodeMirror.tsx @@ -228,6 +228,12 @@ export const CodeMirror = React.forwardRef( }); const parentDiv = wrapper.current; + const existingPlaceholder = parentDiv.querySelector( + ".sp-pre-placeholder" + ); + if (existingPlaceholder) { + parentDiv.removeChild(existingPlaceholder); + } const view = new EditorView({ state: startState, @@ -350,9 +356,7 @@ export const CodeMirror = React.forwardRef( if (readOnly) { return (
-          {!shouldInitEditor && (
-            {code}
-          )}
+          {code}
 
           {readOnly && showReadOnly && (
             Read-only
@@ -376,16 +380,14 @@ export const CodeMirror = React.forwardRef(
         tabIndex={0}
         translate="no"
       >
-        {!shouldInitEditor && (
-          
-            {code}
-          
- )} +
+          {code}
+        
<>