I have the following strange problem with a custom element running codemirror (6.0.1) hosted by an Elm app. If I open the editor (push a button in the app), codemirror displays the correct source text and behaves as it should. Now I close the editor (another button push) and open it again. This time the codemirror editor displays a blank screen. What is odd is that in both the good and the bad cases the function setEditorText
listed below logs the same data to the console when it is called the first and second times.
See also the log of editor activity below.
Many thanks in advance for your help.
function setEditorText(editor, str) {
const currentValue = editor.state.doc.toString();
const endPosition = currentValue.length;
console.log("@@(CM) function setEditorText (1), str.length ", str.length)
console.log("@@(CM) function setEditorText (2), from, to ", 0, endPosition)
editor.dispatch({
changes: {
from: 0,
to: endPosition,
insert: str
}
})
}
Log of editor activity
Lines F ...
are events in the host Elm app
Lines @@(CM) ...
come from console.log statements in codemirror
F : OpenEditor
F : ClearEditorContent
F : SetInitialEditorContent
@@(CM) function setEditorText (1), str.length 31409
@@(CM) function setEditorText (2), from, to 0 31409
------------------------------------------------------
F : CloseEditor
------------------------------------------------------
F : OpenEditor
F : ClearEditorContent
F : SetInitialEditorContent
@@(CM) function setEditorText (1), str.length 31409
@@(CM) function setEditorText (2), from, to 0 31409