import {
  Entity,
  EditorState,
  AtomicBlockUtils
} from 'draft-js'

export default (editorState, url) => {
  const urlType = 'embed'
  const entityKey = Entity.create(urlType, 'IMMUTABLE', { src: url })
  const newEditorState = AtomicBlockUtils.insertAtomicBlock(
    editorState,
    entityKey,
    ' '
  )
  return EditorState.forceSelection(
    newEditorState,
    editorState.getCurrentContent().getSelectionAfter()
  )
}

import {
  Entity,
  EditorState,
  AtomicBlockUtils
} from 'draft-js'

export default (editorState, url) => {
  const urlType = 'embed'
  const entityKey = Entity.create(urlType, 'IMMUTABLE', { src: url })
  const newEditorState = AtomicBlockUtils.insertAtomicBlock(
    editorState,
    entityKey,
    ' '
  )
  return EditorState.forceSelection(
    newEditorState,
    newEditorState.getCurrentContent().getSelectionAfter()
  )
}

Move cursor after embed when inserting
Move cursor after embed when inserting

Right now, when you insert an embed the cursor is afterwards _above_ the embed, rather than below it. With this fix the cursor is correctly moved after the embed, which makes for a much nicer writing experience.

Reference `image-plugin` PR with the same fix: https://github.com/draft-js-plugins/draft-js-plugins/pull/928