Skip to content

Commit e0d9cf7

Browse files
committed
fix dropping image from Firefox on Linux
1 parent 10ea5d0 commit e0d9cf7

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

browser/main/lib/dataApi/attachmentManagement.js

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -304,32 +304,34 @@ function handleAttachmentDrop (codeEditor, storageKey, noteKey, dropEvent) {
304304
}
305305
}))
306306
} else {
307-
promise = Promise.all(Array.from(dropEvent.dataTransfer.items).map(item => {
308-
if (item.type === 'text/html') {
309-
const html = dropEvent.dataTransfer.getData('text/html')
310-
311-
const match = /<img[^>]*[\s"']src="([^"]+)"/.exec(html)
312-
if (match) {
313-
const imageURL = match[1]
314-
315-
return getImage(imageURL)
316-
.then(image => {
317-
const canvas = document.createElement('canvas')
318-
const context = canvas.getContext('2d')
319-
canvas.width = image.width
320-
canvas.height = image.height
321-
context.drawImage(image, 0, 0)
322-
323-
return copyAttachment({type: 'base64', data: canvas.toDataURL(), sourceFilePath: imageURL}, storageKey, noteKey)
324-
})
325-
.then(fileName => ({
326-
fileName,
327-
title: imageURL,
328-
isImage: true
329-
}))
330-
}
307+
let imageURL = dropEvent.dataTransfer.getData('text/plain')
308+
309+
if (!imageURL) {
310+
const match = /<img[^>]*[\s"']src="([^"]+)"/.exec(dropEvent.dataTransfer.getData('text/html'))
311+
if (match) {
312+
imageURL = match[1]
331313
}
332-
}))
314+
}
315+
316+
if (!imageURL) {
317+
return
318+
}
319+
320+
promise = Promise.all([getImage(imageURL)
321+
.then(image => {
322+
const canvas = document.createElement('canvas')
323+
const context = canvas.getContext('2d')
324+
canvas.width = image.width
325+
canvas.height = image.height
326+
context.drawImage(image, 0, 0)
327+
328+
return copyAttachment({type: 'base64', data: canvas.toDataURL(), sourceFilePath: imageURL}, storageKey, noteKey)
329+
})
330+
.then(fileName => ({
331+
fileName,
332+
title: imageURL,
333+
isImage: true
334+
}))])
333335
}
334336

335337
promise.then(files => {

0 commit comments

Comments
 (0)