Преглед изворни кода

fix: improved copy text helper function (#8677)

master
Calinteodor пре 4 година
родитељ
комит
87a110b9c3
No account linked to committer's email address
2 измењених фајлова са 4 додато и 13 уклоњено
  1. 2
    2
      react/features/base/buttons/CopyButton.js
  2. 2
    11
      react/features/base/util/helpers.js

+ 2
- 2
react/features/base/buttons/CopyButton.js Прегледај датотеку

@@ -2,9 +2,9 @@
2 2
 
3 3
 import React, { useState } from 'react';
4 4
 
5
-import { translate } from '../../base/i18n';
6 5
 import { Icon, IconCheck, IconCopy } from '../../base/icons';
7
-import { copyText } from '../../base/util';
6
+import { translate } from '../i18n';
7
+import { copyText } from '../util';
8 8
 
9 9
 
10 10
 type Props = {

+ 2
- 11
react/features/base/util/helpers.js Прегледај датотеку

@@ -31,24 +31,15 @@ export function assignIfDefined(target: Object, source: Object) {
31 31
  * @param {string} textToCopy - Text to be copied.
32 32
  * @returns {boolean}
33 33
  */
34
-export function copyText(textToCopy: string) {
35
-    const fakeTextArea = document.createElement('textarea');
34
+export async function copyText(textToCopy: string) {
36 35
     let result;
37 36
 
38
-    // $FlowFixMe
39
-    document.body.appendChild(fakeTextArea);
40
-    fakeTextArea.value = textToCopy;
41
-    fakeTextArea.select();
42
-
43 37
     try {
44
-        result = document.execCommand('copy');
38
+        result = await navigator.clipboard.writeText(textToCopy);
45 39
     } catch (err) {
46 40
         result = false;
47 41
     }
48 42
 
49
-    // $FlowFixMe
50
-    document.body.removeChild(fakeTextArea);
51
-
52 43
     return result;
53 44
 }
54 45
 

Loading…
Откажи
Сачувај