存在 textEditor 需要插入一些纯文本内容,我尝试使用 EditorState.push 方法,我认为它适用于这种情况。我尝试这样的事情:
const { ContentState: { createFromText }, EditorState: { createWithContent, push }} = DraftJS;
export const pushTextToCurrentEditorState = (text, editorState) => {
const textContentState = createFromText(text);
const newEditorState = push(editorState, textContentState, 'insert-characters');
// debugger;
console.log(editorStateToJSON(editorState))
console.log(editorStateToJSON(newEditorState))
return JSON.parse(editorStateToJSON(newEditorState));
}
结果newEditorState
不是合并状态,而是替换了一个,老的editorState错过了,newEditorState
变成了全新的东西,就像create from the text
. 这里有什么错误的用法吗?还是有其他方法可以解决问题?