我想知道在使用键盘命令插入文本后,如何在draft.js中更改光标位置。因此,我目前正在使用_handleKeyCommand(cmd)
,以便在用户按下特定按钮时插入自定义文本块。接下来,我尝试了以下方法:
currentState = this.state.editorState;
var selectionState = this.state.editorState.getSelection().getStartKey();
this.setState({editorState: EditorState.forceSelection(currentState, selectionState)});
但是这个程序一直崩溃并显示错误信息:
TypeError: selection.getHasFocus 不是一个函数
尽管我已经导入了 SelectionState
。那么我要如何正确地改变光标位置(最好是在插入之前的位置),我在这里做错了什么?
selectionState=selectionState.merge({'forceKey':xxxx, focusOffset:5})
- Jiang YDelement
转换为block
,那么请将focusOffset
设置为该块文本的长度。 - Jiang YD