Skip to content

Commit

Permalink
Backport PR jupyterlab#7202: Allow different mimetypes for the clipbo…
Browse files Browse the repository at this point in the history
…ard data
  • Loading branch information
blink1073 authored and MeeseeksDev[bot] committed Sep 18, 2019
1 parent 15d0c23 commit 04cf2c6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/apputils/src/clipboard.ts
Expand Up @@ -3,6 +3,9 @@

import { MimeData } from '@phosphor/coreutils';

// 'string' is allowed so as to make it non-breaking for any 1.x releases
export type ClipboardData = string | MimeData;

/**
* The clipboard interface.
*/
Expand All @@ -27,11 +30,17 @@ export namespace Clipboard {
* #### Notes
* This can only be called in response to a user input event.
*/
export function copyToSystem(text: string): void {
export function copyToSystem(clipboardData: ClipboardData): void {
let node = document.body;
let handler = (event: ClipboardEvent) => {
let data = event.clipboardData || (window as any).clipboardData;
data.setData('text', text);
if (typeof clipboardData === 'string') {
data.setData('text', clipboardData);
} else {
(clipboardData as MimeData).types().map((mimeType: string) => {
data.setData(mimeType, clipboardData.getData(mimeType));
});
}
event.preventDefault();
node.removeEventListener('copy', handler);
};
Expand Down

0 comments on commit 04cf2c6

Please sign in to comment.