Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow different mimetypes for the clipboard data #7202

Merged
merged 1 commit into from Sep 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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