有一个关于草案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.视频块。
发布于 2018-08-31 00:36:34
好的。问题在selectionState中。
初始化初始状态时,selectionState (锚点和焦点的位置)等于第一个块的第一个字符。因此,AtomicBlockUtils.insertAtomicBlock方法将在selectionState和插入“原子”之间拆分块。
决定:EditorsState.moveSelectionToEnd(editorState)。
https://stackoverflow.com/questions/52064240
复制相似问题