How to change cursor position with draft.js?

让人想犯罪 __ 提交于 2020-01-04 05:54:11

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/47123963/how-to-change-cursor-position-with-draft-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!