Reset state of codemirror

Is there a way to reset the state of the codemirror editor? My problem is that in certain circumstances the code

editor.dispatch({
            changes: {
                from: 0,
                to: endPosition,
                insert: str
            }
        })

does not display the new text in the editor, despite the fact that I’ve verified that str and endPosition are correct. In this situation, I would like to reset the editor state and then do the dispatch.

EditorView.setState is what you want. Though if you have a minimal program that demonstrates the document not being redrawn when you replace it the way you show, I’d like to look at that, since that would be a bug.

I will try to make a simple JS-only demo that illustrates the problem. Meanwhile, I’ve found a workaround that serves as a stopgap.