From 2994420160314feb4147659d2abe654d7a0c45a7 Mon Sep 17 00:00:00 2001 From: Hung Nguyen Date: Tue, 17 Apr 2018 20:47:13 +0700 Subject: [PATCH] Fixed image not displaying after paste --- browser/components/CodeEditor.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index 872e9ad7..809957da 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -331,9 +331,14 @@ export default class CodeEditor extends React.Component { const imageDir = path.join(storagePath, 'images') if (!fs.existsSync(imageDir)) fs.mkdirSync(imageDir) const imagePath = path.join(imageDir, `${imageName}.png`) - fs.writeFile(imagePath, binaryData, 'binary') - const imageMd = `![${imageName}](${path.join('/:storage', `${imageName}.png`)})` - this.insertImageMd(imageMd) + fs.writeFile(imagePath, binaryData, 'binary', (error) => { + if (error) { + throw error + } else { + const imageMd = `![${imageName}](${path.join('/:storage', `${imageName}.png`)})` + this.insertImageMd(imageMd) + } + }) } } else if (this.props.fetchUrlTitle && isURL(pastedTxt) && !isInLinkTag(editor)) { this.handlePasteUrl(e, editor, pastedTxt)