facebookarchive/draft-js

Out of sync selectionState within decorator strategy

オープン

#484 opened on 2016/06/23

 (4 件のコメント) (1 件のリアクション) (0 人の担当者)JavaScript (2,646 件のフォーク)batch import
help wantedquestion

Repository metrics

Stars
 (22,554 個のスター)
PR merge metrics
 (PR metrics pending)

説明

It would be nice for developers to be able to get the selectionState within a decorator strategy. When trying to do this with this.state.editorState.getSelection() inside of the decorator, the data seems to be out of sync.

Try creating a decorator with this strategy

strategy: (contentBlock, callback) =>  {
     const editorStateText = this.state.editorState.getCurrentContent().getPlainText();
     const contentBlockText = contentBlock.getText();

     console.log(editorStateText);
     console.log(contentBlockText);

     //...
},

You will notice that contentBlockText will be one character(or keystroke) ahead of editorStateText when typing.

Does getting an up-to-date selectionState within the decorator strategy seem like a good idea?

コントリビューターガイド