From f120af445cddb7719a66c2e54fffa10b54fcf859 Mon Sep 17 00:00:00 2001 From: Mu-An Chiou Date: Tue, 5 Nov 2019 15:55:10 -0500 Subject: [PATCH 1/2] Use copyText to copy input value we don't have to maintain multiple ways of copying string --- src/clipboard-copy-element.js | 8 ++------ src/clipboard.js | 14 +------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/clipboard-copy-element.js b/src/clipboard-copy-element.js index aebdcc8..c8f6920 100644 --- a/src/clipboard-copy-element.js +++ b/src/clipboard-copy-element.js @@ -1,6 +1,6 @@ /* @flow strict */ -import {copyInput, copyNode, copyText} from './clipboard' +import {copyNode, copyText} from './clipboard' function copy(button: HTMLElement) { const id = button.getAttribute('for') @@ -22,11 +22,7 @@ function copy(button: HTMLElement) { function copyTarget(content: Element) { if (content instanceof HTMLInputElement || content instanceof HTMLTextAreaElement) { - if (content.type === 'hidden') { - return copyText(content.value) - } else { - return copyInput(content) - } + return copyText(content.value) } else if (content instanceof HTMLAnchorElement && content.hasAttribute('href')) { return copyText(content.href) } else { diff --git a/src/clipboard.js b/src/clipboard.js index bbaf6b9..65c04ca 100644 --- a/src/clipboard.js +++ b/src/clipboard.js @@ -53,17 +53,5 @@ export function copyText(text: string): Promise { } export function copyInput(node: HTMLInputElement | HTMLTextAreaElement): Promise { - if ('clipboard' in navigator) { - // eslint-disable-next-line flowtype/no-flow-fix-me-comments - // $FlowFixMe Clipboard is not defined in Flow yet. - return navigator.clipboard.writeText(node.value) - } - - node.select() - document.execCommand('copy') - const selection = getSelection() - if (selection != null) { - selection.removeAllRanges() - } - return Promise.resolve() + return copyText(node.value) } From a3b00f476f09fcb5430946a369e7a47c771f65a4 Mon Sep 17 00:00:00 2001 From: Mu-An Chiou Date: Tue, 5 Nov 2019 16:03:46 -0500 Subject: [PATCH 2/2] Remove unused exported function --- src/clipboard.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/clipboard.js b/src/clipboard.js index 65c04ca..add7520 100644 --- a/src/clipboard.js +++ b/src/clipboard.js @@ -51,7 +51,3 @@ export function copyText(text: string): Promise { body.removeChild(node) return Promise.resolve() } - -export function copyInput(node: HTMLInputElement | HTMLTextAreaElement): Promise { - return copyText(node.value) -}