entity: getEntityKeyForSelection()

in src/component/handlers/edit/editOnPaste.js [66:186]


          entity: getEntityKeyForSelection(
            editorState.getCurrentContent(),
            editorState.getSelection(),
          ),
        });
        const currentBlockType =
          RichTextEditorUtil.getCurrentBlockType(editorState);

        const text = DraftPasteProcessor.processText(
          blocks,
          character,
          currentBlockType,
        );
        const fragment = BlockMapBuilder.createFromArray(text);

        const withInsertedText = DraftModifier.replaceWithFragment(
          editorState.getCurrentContent(),
          editorState.getSelection(),
          fragment,
        );

        editor.update(
          EditorState.push(editorState, withInsertedText, 'insert-fragment'),
        );
      });

      return;
    }
  }

  let textBlocks: Array<string> = [];
  let text: string = (data.getText(): any);
  let html: string = (data.getHTML(): any);
  const editorState = editor._latestEditorState;

  if (editor.props.formatPastedText) {
    const {text: formattedText, html: formattedHtml} =
      editor.props.formatPastedText(text, html);
    text = formattedText;
    html = ((formattedHtml: any): string);
  }

  if (text) {
    textBlocks = splitTextIntoTextBlocks(text);
  }

  let handleInternalPaste: ?() => void = null;

  if (!editor.props.stripPastedStyles) {
    // If the text from the paste event is rich content that matches what we
    // already have on the internal clipboard, assume that we should just use
    // the clipboard fragment for the paste. This will allow us to preserve
    // styling and entities, if any are present. Note that newlines are
    // stripped during comparison -- this is because copy/paste within the
    // editor in Firefox and IE will not include empty lines. The resulting
    // paste will preserve the newlines correctly.
    const internalClipboard = editor.getClipboard();
    if (
      !editor.props.formatPastedText &&
      data.isRichText() &&
      internalClipboard
    ) {
      if (
        // If the editorKey is present in the pasted HTML, it should be safe to
        // assume this is an internal paste.
        html?.indexOf(editor.getEditorKey()) !== -1 ||
        // The copy may have been made within a single block, in which case the
        // editor key won't be part of the paste. In this case, just check
        // whether the pasted text matches the internal clipboard.
        (textBlocks.length === 1 &&
          internalClipboard.size === 1 &&
          internalClipboard.first().getText() === text)
      ) {
        handleInternalPaste = () =>
          editor.update(
            insertFragment(editor._latestEditorState, internalClipboard),
          );
      }
    } else if (
      internalClipboard &&
      data.types.includes('com.apple.webarchive') &&
      !data.types.includes('text/html') &&
      areTextBlocksAndClipboardEqual(textBlocks, internalClipboard)
    ) {
      // Safari does not properly store text/html in some cases.
      // Use the internalClipboard if present and equal to what is on
      // the clipboard. See https://bugs.webkit.org/show_bug.cgi?id=19893.
      handleInternalPaste = () =>
        editor.update(
          insertFragment(editor._latestEditorState, internalClipboard),
        );
    }

    if (
      editor.props.handlePastedText &&
      isEventHandled(
        editor.props.handlePastedText(
          text,
          html,
          editorState,
          handleInternalPaste != null,
        ),
      )
    ) {
      return;
    }

    if (handleInternalPaste != null) {
      handleInternalPaste();
      return;
    }

    // If there is html paste data, try to parse that.
    if (html) {
      const htmlFragment = DraftPasteProcessor.processHTML(
        html,
        editor.props.blockRenderMap,
      );
      if (htmlFragment) {
        const {contentBlocks, entityMap} = htmlFragment;
        if (contentBlocks) {