2

I have created an editor using Slate js in react. I am trying to insert a block at the end of the editor content. I came across a method to insert block at the range. How to specify the range of the document such that my custom blocks gets added at the end of the content but focus stays at the current selection and not at the end of the document.

function insertFile(editor, src, target) {
  editor.insertBlock({
    type: 'file',
    data: { src },
  })
}

My schema looks like this

const schema = {
  blocks: {
    file:{
      isVoid: true
    }
  }
}

1 Answer 1

4

Using the Transforms object, it behaves just like you wished.

import { Transforms } from 'slate'

Transforms.insertNodes(
    editor,
    { type: 'paragraph', children: [{ text: 'xxxx' }] },
    { at: [editor.children.length] }
)

To see the document for this: Link1 Link2

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.