我正在尝试从 Draft-js 编辑器外部删除图像,但它始终插入到编辑器中光标/选择的最后位置(或者如果未设置光标/选择,则在末尾)。
这是我的环绕draft-js-drag-n-drop-plugin
const droppableBlockDndPlugin = {
...blockDndPlugin,
handleDrop: (
selection,
dataTransfer,
isInternal,
{getEditorState, setEditorState}
) => {
const editorState = getEditorState();
const raw = dataTransfer.data.getData('text');
const data = raw ? raw.split(IMAGE_BLOCK_TYPE_SEPARATOR) : [];
if (data.length > 1 && data[0] === IMAGE_BLOCK_TYPE_PURE) {
const url = data[1];
if (url) {
const newState = imagePlugin.addImage(editorState, url);
setEditorState(newState);
}
}
return blockDndPlugin.handleDrop(selection, dataTransfer, isInternal, {
getEditorState,
setEditorState
});
}
};
基本上我只是在handleDrop
使用插入图像的基础发生之前做额外的逻辑imagePlugin.addImage
。有没有办法将图像拖放到拖动位置?