How to clear document?


#1

Hi,

How to reset editor state or “clear document”? I tried to reset it through setting view to default document with window.editor.view.updateState({doc, ...window.editor.state.config}) but that leads to

Uncaught TypeError: Cannot read property '$head' of undefined
    at needsCursorWrapper (index.js:2250)
    at updateCursorWrapper (index.js:4487)
    at EditorView.updateState (index.js:4225)
    at <anonymous>:1:20
function needsCursorWrapper(state) {
  var ref = state.selection;
  var $head = ref.$head;  // <-- here 

#2

States have to be instances of EditorState—you can’t just pass an object literal. Wrapping that literal in EditorState.create will probably work.


#3

That helped a bit. Now it’s TypeError: plugins is undefined error in

EditorView.prototype.updatePluginViews = function updatePluginViews (prevState) {
    var this$1 = this;

  var plugins = this.state.plugins;
  if (!prevState || prevState.plugins != plugins) {
    this.destroyPluginViews();
    for (var i = 0; i < plugins.length; i++) { // <-- here