pasteHTML function

void pasteHTML(
  1. EditorState editorState,
  2. String html
)

Implementation

void pasteHTML(EditorState editorState, String html) {
  final selection = editorState.selection?.normalized;
  if (selection == null || !selection.isCollapsed) {
    return;
  }

  Log.keyboard.debug('paste html: $html');

  final htmlToNodes = htmlToDocument(html).root.children.where((element) {
    final delta = element.delta;
    if (delta == null) {
      return true;
    }
    return delta.isNotEmpty;
  });
  if (htmlToNodes.isEmpty) {
    return;
  }

  if (htmlToNodes.length == 1) {
    _pasteSingleLineInText(
      editorState,
      selection.startIndex,
      htmlToNodes.first,
    );
  } else {
    _pasteMultipleLinesInText(
      editorState,
      selection.start.offset,
      htmlToNodes.toList(),
    );
  }
}