2017-08-21 18 views
1

Draft.jsにコンテンツといくつかのデコレータを含むEditorStateを作成した後で、カーソル位置を設定する方法を教えてください。それは、常にこれは何が起こるかである位置0Draft.jsを使用して文字列から状態を作成するときにカーソル位置を設定する

で開始:

enter image description here

これは私が欲しいものです:私は状態を作成していますか

ここ

enter image description here

です。

constructor(props) { 
    super(props) 
    this.state = { editorState: this.getEditorState() } 
    } 

    getEditorState() { 
    const { reply: { channel, userAccount } } = this.props 
    const content = this.getEditorContent({ channel, userAccount }) 
    const decorators = this.getEditorDecorators(channel) 
    return EditorState.createWithContent(content, decorators) 
    } 

    getEditorContent({ channel, userAccount }) { 
    const content = channel && channel.prefill(userAccount) 
    return ContentState.createFromText(content || '') 
    } 

    getEditorDecorators({ decorators }) { 
    return getDecorators(decorators || []) 
    } 

答えて

2

Draft.jsリポジトリからissue 224を読んだ後、私はmoveSelectionToEndという静的メソッドを見つけました。私がしなければならないことはすべて、この方法でまったく新しい状態をラップすることです。

getEditorState() { 
    const { reply: { channel, userAccount } } = this.props 
    const content = this.getEditorContent({ channel, userAccount }) 
    const decorators = this.getEditorDecorators(channel) 
    const state = EditorState.createWithContent(content, decorators) 
    return EditorState.moveSelectionToEnd(state) 
    } 
関連する問題