mirror of
https://github.com/strapi/strapi.git
synced 2025-11-11 15:49:50 +00:00
Fixes #978
This commit is contained in:
parent
587197c00f
commit
58e16b8d4c
@ -590,22 +590,40 @@ class Wysiwyg extends React.Component {
|
|||||||
'X-Forwarded-Host': 'strapi',
|
'X-Forwarded-Host': 'strapi',
|
||||||
};
|
};
|
||||||
|
|
||||||
const newContentState = this.createNewContentStateFromBlock(
|
let newEditorState = this.getEditorState();
|
||||||
createNewBlock(`![Uploading ${files[0].name}]()`),
|
|
||||||
);
|
const nextBlocks = getNextBlocksList(newEditorState, this.getSelection().getStartKey());
|
||||||
const newEditorState = EditorState.push(this.getEditorState(), newContentState);
|
// Loop to update each block after the inserted li
|
||||||
this.setState({ editorState: newEditorState });
|
nextBlocks.map((block, index) => {
|
||||||
|
// Update the current block
|
||||||
|
const nextBlockText = index === 0 ? `![Uploading ${files[0].name}]()` : nextBlocks.get(index - 1).getText();
|
||||||
|
const newBlock = createNewBlock(nextBlockText, 'unstyled', block.getKey());
|
||||||
|
// Update the contentState
|
||||||
|
const newContentState = this.createNewContentStateFromBlock(
|
||||||
|
newBlock,
|
||||||
|
newEditorState.getCurrentContent(),
|
||||||
|
);
|
||||||
|
newEditorState = EditorState.push(newEditorState, newContentState);
|
||||||
|
});
|
||||||
|
|
||||||
|
const offset = `![Uploading ${files[0].name}]()`.length;
|
||||||
|
const updatedSelection = updateSelection(this.getSelection(), nextBlocks, offset);
|
||||||
|
this.setState({ editorState: EditorState.acceptSelection(newEditorState, updatedSelection) });
|
||||||
|
|
||||||
return request('/upload', { method: 'POST', headers, body: formData }, false, false)
|
return request('/upload', { method: 'POST', headers, body: formData }, false, false)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
const lastBlock = this.getEditorState()
|
const nextBlockKey = newEditorState
|
||||||
.getCurrentContent()
|
.getCurrentContent()
|
||||||
.getLastBlock();
|
.getKeyAfter(newEditorState.getSelection().getStartKey());
|
||||||
|
const content = ``;
|
||||||
const newContentState = this.createNewContentStateFromBlock(
|
const newContentState = this.createNewContentStateFromBlock(
|
||||||
createNewBlock(``, 'unstyled', lastBlock.getKey()),
|
createNewBlock(content, 'unstyled', nextBlockKey),
|
||||||
);
|
);
|
||||||
const newEditorState = EditorState.push(this.getEditorState(), newContentState);
|
|
||||||
this.setState({ editorState: EditorState.moveFocusToEnd(newEditorState) });
|
newEditorState = EditorState.push(newEditorState, newContentState);
|
||||||
|
const updatedSelection = updateSelection(this.getSelection(), nextBlocks, 2);
|
||||||
|
|
||||||
|
this.setState({ editorState: EditorState.acceptSelection(newEditorState, updatedSelection) });
|
||||||
this.sendData(newEditorState);
|
this.sendData(newEditorState);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user