import { SelectionState , EditorState , ContentBlock } from 'draft-js' ; import DraftOffsetKey from 'draft-js/lib/DraftOffsetKey' ; export default ( getEditorState , setEditorState , newActiveBlock ) : void => { const editorState = getEditorState ( ) ; const offsetKey = DraftOffsetKey . encode ( newActiveBlock . getKey ( ) , 0 , 0 ) ; const node = document . querySelectorAll ( `[data-offset-key="${ offsetKey }"]` ) [ 0 ] ; const selection = window . getSelection ( ) ! ; const range = document . createRange ( ) ; range . setStart ( node , 0 ) ; range . setEnd ( node , 0 ) ; selection . removeAllRanges ( ) ; selection . addRange ( range ) ; setEditorState ( EditorState . forceSelection ( editorState , new SelectionState ( { anchorKey : newActiveBlock . getKey ( ) , anchorOffset : 0 , focusKey : newActiveBlock . getKey ( ) , focusOffset : 0 , isBackward : false , } ) ) ) ; } ;