message: cursor moves to correct position after paste (testing slate fix)
diff: @@ -106,7 +106,13 @@ export const createTextEditor = (
  return (
  <Editor
  - ref={editor as React.RefObject<Editor>}
  + ref={slateReact => {
  + if (slateReact && !editor.current) {
  + editor.current = slateReact
  + patchSlateInsertFragment(slateReact)
  + }
  + }}
  + // ref={editor as React.RefObject<Editor>}
  onPaste={createOnPaste(slateClosure)}
  onKeyDown={createOnKeyDown(slateClosure)}
  onClick={(e, editor, next): CoreEditor | void => {
  @@ -377,3 +383,68 @@ interface SlateClosure extends SlateEditorAdditionalProps {
  focusNext: () => void
  plugins: Record<string, Plugin>
  }
  +
  +// TEMPORARY
  +// Testbed for integration of slate fix
  +// polyfilling slate editor
  +function patchSlateInsertFragment(reacteditor: Editor) {
  + // @ts-ignore
  + const editor = reacteditor as CoreEditor
  + // @ts-ignore
  + editor.insertFragment = fragment => {
  + if (!fragment.nodes.size) return editor
  +
  + if (editor.value.selection.isExpanded) {
  + editor.delete()
  + }
  +
  + let { value } = editor
  + let { document, selection } = value
  + const { start, end } = selection
  + const { startText, endText, startInline } = value
  + const lastText = fragment.getLastText()
  + // @ts-ignore
  + const lastInline = fragment.getClosestInline(lastText.key)
  + // @ts-ignore
  + const lastBlock = fragment.getClosestBlock(lastText.key)
  + const firstChild = fragment.nodes.first()
  + const lastChild = fragment.nodes.last()
  + // @ts-ignore
  + const keys = document.getTexts().map(text => text.key)
  + const isAppending =
  + !startInline ||
  + (start.isAtStartOfNode(startText) || end.isAtStartOfNode(startText)) ||
  + (start.isAtEndOfNode(endText) || end.isAtEndOfNode(endText))
  +
  + const isInserting =
  + firstChild.hasBlockChildren() || lastChild.hasBlockChildren()
  +
  + // @ts-ignore
  + editor.insertFragmentAtRange(selection, fragment)
  + value = editor.value
  + document = value.document
  +
  + // @ts-ignore
  + const newTexts = document.getTexts().filter(n => !keys.includes(n.key))
  + const newText = isAppending ? newTexts.last() : newTexts.takeLast(2).first()
  +
  + if (newText && (lastInline || isInserting)) {
  + editor.moveToEndOfNode(newText)
  + } else if (newText && lastBlock) {
  + // Changed code
  + const lastInlineIndex = lastBlock.nodes.findLastIndex(node => {
  + if (!node) return false
  + return node.object == 'inline'
  + })
  + const skipLength = lastBlock.nodes
  + .takeLast(lastBlock.nodes.size - lastInlineIndex - 1)
  + .reduce((num, v) => {
  + if (!num) num = 0
  + if (v) return num + v.text.length
  + return num
  + }, 0)
  + editor.moveToStartOfNode(newText).moveForward(skipLength)
  + }
  + return editor
  + }
  +}
  