stephenLYZ commented on code in PR #20058:
URL: https://github.com/apache/superset/pull/20058#discussion_r873862814


##########
superset-frontend/src/utils/copy.ts:
##########
@@ -17,40 +17,73 @@
  * under the License.
  */
 
-const copyTextToClipboard = async (text: string) =>
-  new Promise<void>((resolve, reject) => {
-    const selection: Selection | null = document.getSelection();
-    if (selection) {
-      selection.removeAllRanges();
-      const range = document.createRange();
-      const span = document.createElement('span');
-      span.textContent = text;
-      span.style.position = 'fixed';
-      span.style.top = '0';
-      span.style.clip = 'rect(0, 0, 0, 0)';
-      span.style.whiteSpace = 'pre';
-
-      document.body.appendChild(span);
-      range.selectNode(span);
-      selection.addRange(range);
-
-      try {
-        if (!document.execCommand('copy')) {
+// Use the new Clipboard API if the browser supports it
+const copyTextWithClipboardApi = async (getText: () => Promise<string>) => {
+  try {

Review Comment:
   Actually It is not recommended to use nested try catches from async/await, 
which cause errors to bubble up, meaning that all functions under the catch 
scope are called (You can see copy is called twice in the chrome). I think It 
is okay to guarantee top-level try catches,  maybe more appropriate to use 
promise here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to