0

有一个关于草稿js的问题。

我如何更改 ContentBlocks 的顺序?我试图在编辑器中添加内容的外部链接并渲染视频。

创建当前状态:

createEditorState(source) {
        if (!source) {
          return EditorState.createEmpty();
        }

        const contentState = stateFromMarkdown(source);
        const editorState = EditorState.createWithContent(contentState);

        return addVideoContent(source, editorState)
 }

添加带有视频内容的块(支持通过视频插件呈现):

addVideoContent(source, editorState) {
    function buildNewEditorState(state, src) {
      const currentContentState = state.getCurrentContent();
      const contentStateWithEntity = currentContentState
        .createEntity(VIDEO_PLUGIN_TYPE, 'IMMUTABLE', { src });
      const entityKey = contentStateWithEntity.getLastCreatedEntityKey();

      return AtomicBlockUtils.insertAtomicBlock(state, entityKey, ' ');
    }

    //defining video urls
    ...

    return videoUrls.reduce(buildNewEditorState, editorState);
}

问题在于渲染顺序: 1. 视频块;2.链接块。

如何将此顺序更改为: 1. 链接块;2.视频块。

4

1 回答 1

1

好的。问题是在选择状态。

初始化初始状态时,selectionState(锚点和焦点的位置)等于第一个块的第一个字符。因此AtomicBlockUtils.insertAtomicBlock方法将在 selectionState 和插入“原子”之间拆分块。

决定:EditorsState.moveSelectionToEnd(editorState)

于 2018-08-30T16:36:34.120 回答