複数のテキスト入力が必要なアプリケーションがあります。書式設定とカスタマイズのために私はdraft-js
をエディタとして選択しましたが、非常に厄介な入力問題が発生しました。入力を逆転させるDraft-jsエディタ
私がエディタに入力すると、最後に押されたキーがエディタの先頭に印刷され、入力全体が反転されます。つまり、常にキャレットがその行の最初のインデックスにあるかのようです。
私は3つのエディタを持っていますが、それぞれには1つのonChangeがあり、それは最新のエディタでreduxストアを更新します。contentState
ページが再レンダリングされると、それぞれのエディタはcontentState
でレンダリングされ、EditorState
に変換されます。ここで
私のコードです:
main.js
render() {
/* Each Editor has a similar block as below */
let coverEditorState = EditorState.createEmpty()
let coverContentState = _.get(data, 'details.message.cover.contentState')
if (typeof coverContentHTML != "undefined"){
coverEditorState = EditorState.createWithContent(coverContentState)
}
return (
...
<Composer
editorState={coverEditorState}
onChange={this._handleCoveringLetterChange.bind(this)}
/>
...
)
}
Composer.js
class Composer extends Component {
constructor() {
super()
this.state = { editorState: EditorState.createEmpty(), styleMap: {} }
}
componentWillReceiveProps(nextProps) {
this.setState({ editorState: nextProps.editorState })
}
onChange(editorState) {
let nextState = Object.assign({}, this.state, { editorState })
let currentContentState = editorState.getCurrentContent()
let changeObject = {
contentState: currentContentState
}
this.setState(nextState)
this.props.onChange(changeObject)
}
render() {
return (
<Editor
editorState={this.state.editorState}
onChange={this.onChange.bind(this)}
/>
)
}
}
私はSelectionState
などContentState
を返す試してみました2つを組み合わせて再レンダリングしますが、それはより多くの問題とエラー。