Draf JS Sisipkan contoh teks
// 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);
Outstanding Orangutan