You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/05/16 19:55:58 UTC

[GitHub] [superset] diegomedina248 commented on a diff in pull request #20058: fix: Support the Clipboard API in modern browsers

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


##########
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:
   Thanks for that! The change in the parent function (`copyTextToClipboard`) should do it.



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org