import * as im from 'immutable' const removeBlock = (editorState, blockKey) => { const content = editorState.getCurrentContent() const selection = editorState.getSelection() const blockMap = content.getBlockMap().delete(blockKey) return content.merge( { blockMap, selectionAfter: selection }, ) } const addBlock = (state, content, block) => { const selection = SelectionState.createEmpty(block.getKey()) const blocks = content.getBlockMap() const blockKey = block.getKey() const blocksBefore = blocks.takeWhile(x => x.getKey() !== blockKey) const blocksAfter = blocks.skipUntil(x => x.getKey() === blockKey) const newKey = genKey() const data = im.fromJS({ [newKey]: new ContentBlock({ key: newKey, type: 'atomic', text: ' ', data: im.Map({ type: 'placeholder', }), }), }) const newBlocks = blocksBefore.concat(im.fromJS(data)).concat(blocksAfter) return content.merge({ blockMap: newBlocks, selectionAfter: selection, }) }