小编dch*_*en1的帖子

React Draft.js Wysiwyg:如何以编程方式在光标位置插入文本?

我正在使用React Draft Wysiwyg,我需要将应用程序的一个组件中的任意文本插入到编辑器组件中。我通过剪贴板作为从一个组件传输到另一个组件的中介来执行此操作。但是document.execCommand('paste')失败了。

有人知道怎么做这个吗?

我的示例代码在这里;第三个控制台日志为粘贴结果发出 false。

import React, { Component } from 'react';
import { EditorState, convertToRaw, Modifier } from 'draft-js';
import { Editor } from 'react-draft-wysiwyg';
import draftToHtml from 'draftjs-to-html';
import htmlToDraft from 'html-to-draftjs';
import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css';
import styled from 'styled-components';

class EditorConvertToHTML extends Component {
  constructor(props) {
    super(props);
    this.state = {editorState: EditorState.createEmpty()};
    this.onChange = (editorState) => this.setState({editorState});
    this.setEditor = (editor) => {
      this.editor = editor;
    };
    this.focusEditor = () => {
      if (this.editor) {
        this.editor.focusEditor(); …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs draftjs draft-js-plugins react-draft-wysiwyg

0
推荐指数
1
解决办法
4768
查看次数