mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-21 20:15:52 +08:00
check all clipboard contents for Files, not just the first.
This was implemented for the "Copy Image" function of browsers, which on Firefox and Chrome on Linux was tested to give item[0] as "text/html" and item[1] as a file. This effectively worked in rich text mode anyway as it is able to paste text/html snippets, but was unable to work in plain text mode.
This commit is contained in:
parent
0061fc9fc0
commit
c530d31dd5
1 changed files with 25 additions and 24 deletions
|
@ -277,33 +277,34 @@ export function handleFilePasted(event: ClipboardEvent, onFileReceived: (path: s
|
|||
if (event.clipboardData.items.length === 0) {
|
||||
return false;
|
||||
}
|
||||
const item = event.clipboardData.items[0];
|
||||
for (const i in event.clipboardData.items) {
|
||||
const item = event.clipboardData.items[i];
|
||||
// If the pasteboard has a file on it, stream it to a temporary
|
||||
// file and fire our `onFilePaste` event.
|
||||
if (item.kind === 'file') {
|
||||
const temp = require('temp');
|
||||
const blob = item.getAsFile();
|
||||
const ext =
|
||||
{
|
||||
'image/png': '.png',
|
||||
'image/jpg': '.jpg',
|
||||
'image/tiff': '.tiff',
|
||||
}[item.type] || '';
|
||||
|
||||
// If the pasteboard has a file on it, stream it to a temporary
|
||||
// file and fire our `onFilePaste` event.
|
||||
if (item.kind === 'file') {
|
||||
const temp = require('temp');
|
||||
const blob = item.getAsFile();
|
||||
const ext =
|
||||
{
|
||||
'image/png': '.png',
|
||||
'image/jpg': '.jpg',
|
||||
'image/tiff': '.tiff',
|
||||
}[item.type] || '';
|
||||
|
||||
const reader = new FileReader();
|
||||
reader.addEventListener('loadend', () => {
|
||||
const buffer = Buffer.from(new Uint8Array(reader.result as any));
|
||||
const tmpFolder = temp.path('-mailspring-attachment');
|
||||
const tmpPath = path.join(tmpFolder, `Pasted File${ext}`);
|
||||
fs.mkdir(tmpFolder, () => {
|
||||
fs.writeFile(tmpPath, buffer, () => {
|
||||
onFileReceived(tmpPath);
|
||||
const reader = new FileReader();
|
||||
reader.addEventListener('loadend', () => {
|
||||
const buffer = Buffer.from(new Uint8Array(reader.result as any));
|
||||
const tmpFolder = temp.path('-mailspring-attachment');
|
||||
const tmpPath = path.join(tmpFolder, `Pasted File${ext}`);
|
||||
fs.mkdir(tmpFolder, () => {
|
||||
fs.writeFile(tmpPath, buffer, () => {
|
||||
onFileReceived(tmpPath);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
reader.readAsArrayBuffer(blob);
|
||||
return true;
|
||||
reader.readAsArrayBuffer(blob);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const macCopiedFile = decodeURI(ElectronClipboard.read('public.file-url').replace('file://', ''));
|
||||
|
|
Loading…
Add table
Reference in a new issue