From bcb44e8cf7079c14936879cb7ee4c1ef33c17466 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 17 Aug 2018 12:25:21 -0400 Subject: [PATCH] fix copying --- jslib | 2 +- src/app/vault/add-edit.component.ts | 2 +- src/app/vault/ciphers.component.ts | 2 +- src/services/webPlatformUtils.service.ts | 15 ++++++++++++--- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/jslib b/jslib index 1f9fbe43d7..bf9a9c5f9f 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 1f9fbe43d7a78349e6fe994fa70d9b773af5c0f9 +Subproject commit bf9a9c5f9fb5933faeeb07a85f127373ebfe7284 diff --git a/src/app/vault/add-edit.component.ts b/src/app/vault/add-edit.component.ts index 7d8167bffb..c10c178bbe 100644 --- a/src/app/vault/add-edit.component.ts +++ b/src/app/vault/add-edit.component.ts @@ -87,7 +87,7 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit { } this.analytics.eventTrack.next({ action: 'Copied ' + aType }); - this.platformUtilsService.copyToClipboard(value, { doc: window.document }); + this.platformUtilsService.copyToClipboard(value, { window: window }); this.toasterService.popAsync('info', null, this.i18nService.t('valueCopied', this.i18nService.t(typeI18nKey))); } diff --git a/src/app/vault/ciphers.component.ts b/src/app/vault/ciphers.component.ts index 6f8f536374..f757bf32a4 100644 --- a/src/app/vault/ciphers.component.ts +++ b/src/app/vault/ciphers.component.ts @@ -119,7 +119,7 @@ export class CiphersComponent extends BaseCiphersComponent implements OnDestroy } this.analytics.eventTrack.next({ action: 'Copied ' + aType.toLowerCase() + ' from listing.' }); - this.platformUtilsService.copyToClipboard(value, { doc: window.document }); + this.platformUtilsService.copyToClipboard(value, { window: window }); this.toasterService.popAsync('info', null, this.i18nService.t('valueCopied', this.i18nService.t(typeI18nKey))); } diff --git a/src/services/webPlatformUtils.service.ts b/src/services/webPlatformUtils.service.ts index 55dae55f35..9ecc0f568b 100644 --- a/src/services/webPlatformUtils.service.ts +++ b/src/services/webPlatformUtils.service.ts @@ -208,10 +208,19 @@ export class WebPlatformUtilsService implements PlatformUtilsService { } copyToClipboard(text: string, options?: any): void { - const doc: Document = options ? options.doc : window.document; - if ((window as any).clipboardData && (window as any).clipboardData.setData) { + let win = window; + let doc = window.document; + if (options && (options.window || options.win)) { + win = options.window || options.win; + doc = win.document; + } else if (options && options.doc) { + doc = options.doc; + } + if ((win as any).navigator.clipboard && (win as any).navigator.clipboard.writeText) { + (win as any).navigator.clipboard.writeText(text); + } else if ((win as any).clipboardData && (win as any).clipboardData.setData) { // IE specific code path to prevent textarea being shown while dialog is visible. - (window as any).clipboardData.setData('Text', text); + (win as any).clipboardData.setData('Text', text); } else if (doc.queryCommandSupported && doc.queryCommandSupported('copy')) { const textarea = doc.createElement('textarea'); textarea.textContent = text;