facebookarchive/draft-js

Out of sync selectionState within decorator strategy

Open

#484 建立於 2016年6月23日

在 GitHub 查看
 (4 留言) (1 反應) (0 負責人)JavaScript (2,646 fork)batch import
help wantedquestion

倉庫指標

Star
 (22,554 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

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?

貢獻者指南