Help inserting slice on new document

Hi All,

I’ve been trying to take a slice from the current document and insert it in a new EditorState but the ways I tried failed. If I run the transaction against the current view it works so my guess there is something that is incompatible between the selection and the new state or something missing in the new state that doesn’t allow the replaceRange.

let newState = EditorState.create(config);
const slice = this.view.state.selection;
const tr = newState.tr.replaceRange(1,1, slice);
newState = newState.apply(tr);

Any help is appreciated.

Steven

Does config set the new state’s schema to the same schema used in this.view.state?

Oh, an this.view.state.selection does not actually return a slice. So that is probably part of the issue.

@marijn thank you for your help. I found the cause.

I’m using Vue and wrapping the EditorView inside a Vue component.

data() {
  return {
      view: undefined
  }
}

created() {
   this.view = EditorView....
}

Since Vue attaches proxies to the data objects, those proxies may be causing some issue. I moved the view outside of the component and it works fine. This is the code.

let newState = EditorState.create(nkConifg);
const slice = view.state.selection.content();
const tr = newState.tr.replaceRange(1,1,slice);
newState = newState.apply(tr);
this.$emit('onNewDocument', { name: 'linked', content: newState.toJSON() });