let selection = new SelectionState({
anchorKey: 'abc', // key of block
anchorOffset: 5,
focusKey: 'abc',
focusOffset: 10, // key of block
hasFocus: true,
isBackward: false // isBackward = (focusOffset < anchorOffset)
});
let s = new SelectionState(selection);
editorState = EditorState.forceSelection(editorState, s);
// Make sure to set this new EditorState as the editorState of Draft.js component
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter