5

I am wondering how you can change the cursor position in draft.js after having done an text insertion on key command. Therefore I am currently using _handleKeyCommand(cmd) to insert a custom text block whenever the user presses a specific button. Next I tried the following:

currentState = this.state.editorState;
var selectionState = this.state.editorState.getSelection().getStartKey();
this.setState({editorState: EditorState.forceSelection(currentState, selectionState)});

But this keeps crashing with the error message

TypeError: selection.getHasFocus is not a function

although I imported SelectionState. So how do I properly change the cursor position (preferably to the position before the insertion) and what am I doing wrong here?

Xplora
  • 837
  • 3
  • 12
  • 24
nullmn
  • 557
  • 2
  • 7
  • 19

1 Answers1

4

var selectionState = this.state.editorState.getSelection().getStartKey(); should be var selectionState = this.state.editorState.getSelection()

Jiang YD
  • 3,205
  • 1
  • 14
  • 20