如何用draft.js改变光标位置?
How to change cursor position with draft.js?
我想知道如何在按键盘命令插入文本后更改 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 is not a function
虽然我导入了SelectionState
。那么如何正确更改光标位置(最好是插入前的位置)以及我在这里做错了什么?
var selectionState = this.state.editorState.getSelection().getStartKey();
应该是 var selectionState = this.state.editorState.getSelection()
我想知道如何在按键盘命令插入文本后更改 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 is not a function
虽然我导入了SelectionState
。那么如何正确更改光标位置(最好是插入前的位置)以及我在这里做错了什么?
var selectionState = this.state.editorState.getSelection().getStartKey();
应该是 var selectionState = this.state.editorState.getSelection()