reactjs - Programmatically jump to a specific block and move the focus/caret to a decorated word - Stack Overflow

PHOTO EMBED

Fri Sep 17 2021 16:06:23 GMT+0000 (UTC)

Saved by @nabilashraf #javascript

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
content_copyCOPY

DraftJS Selection

https://stackoverflow.com/questions/48286946/programmatically-jump-to-a-specific-block-and-move-the-focus-caret-to-a-decorate