2016-09-16 3 views

ответ

11

Это то, что я в конечном итоге делает:

import { List } from 'immutable' 
import { 
    EditorState, 
    ContentState, 
    ContentBlock, 
    genKey 
} from 'draft-js' 

const addEmptyBlock = (editorState) => { 
    const newBlock = new ContentBlock({ 
    key: genKey(), 
    type: 'unstyled', 
    text: '', 
    characterList: List() 
    }) 

    const contentState = editorState.getCurrentContent() 
    const newBlockMap = contentState.getBlockMap().set(newBlock.key, newBlock) 

    return EditorState.push(
    editorState, 
    ContentState 
     .createFromBlockArray(newBlockMap.toArray()) 
     .set('selectionBefore', contentState.getSelectionBefore()) 
     .set('selectionAfter', contentState.getSelectionAfter()) 
) 
} 
Смежные вопросы