📅  最后修改于: 2022-03-11 15:03:43.839000             🧑  作者: Mango
// get current editor state
const currentContent = editorState.getCurrentContent();
// create new selection state where focus is at the end
const blockMap = currentContent.getBlockMap();
const key = blockMap.last().getKey();
const length = blockMap.last().getLength();
const selection = new SelectionState({
anchorKey: key,
anchorOffset: length,
focusKey: key,
focusOffset: length,
});
//insert text at the selection created above
const textWithInsert = Modifier.insertText(currentContent, selection, 'text to be inserted', null);
const editorWithInsert = EditorState.push(editorState, textWithInsert, 'insert-characters');
//also focuses cursor at the end of the editor
const newEditorState = EditorState.moveSelectionToEnd(editorWithInsert, textWithInsert.getSelectionAfter());
setEditorState(newEditorState);