Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Let `copyText()` take pending text so lazy copies work in Safari

Cursor Agent92a7b565c2da
diff --git a/packages/studio/src/components/Timeline/get-copy-context-for-agents-menu-item.ts b/packages/studio/src/components/Timeline/get-copy-context-for-agents-menu-item.ts
index 4d83cebfbb..eebba64276 100644
--- a/packages/studio/src/components/Timeline/get-copy-context-for-agents-menu-item.ts
+++ b/packages/studio/src/components/Timeline/get-copy-context-for-agents-menu-item.ts
@@ -20,18 +20,17 @@ export const getCopyContextForAgentsMenuItem = ({
return;
}
- const copied =
+ copyText(
typeof contextForAgents === 'string'
- ? copyText(contextForAgents)
+ ? contextForAgents
: contextForAgents().then((context) => {
if (!context) {
throw new Error('No source location found');
}
- return copyText(context);
- });
-
- copied.catch((err) => {
+ return context;
+ }),
+ ).catch((err) => {
showNotification(
`Could not copy to clipboard: ${(err as Error).message}`,
2000,
diff --git a/packages/studio/src/helpers/copy-text.ts b/packages/studio/src/helpers/copy-text.ts
index f40482f00c..733a56e6fe 100644
--- a/packages/studio/src/helpers/copy-text.ts
+++ b/packages/studio/src/helpers/copy-text.ts
@@ -1,3 +1,15 @@
-export const copyText = (cmd: string): Promise<void> => {
- return navigator.clipboard.writeText(cmd);
+export const copyText = (text: string | Promise<string>): Promise<void> => {
+ if (typeof text === 'string') {
+ return navigator.clipboard.writeText(text);
+ }
+
+ // Safari rejects clipboard writes that happen after an async boundary, so
+ // pending text is handed to the clipboard synchronously within the gesture.
+ return navigator.clipboard.write([
+ new ClipboardItem({
+ 'text/plain': text.then(
+ (resolved) => new Blob([resolved], {type: 'text/plain'}),
+ ),
+ }),
+ ]);
};