🎥 Make videos programmatically with React
`@remotion/studio`: Copy agent context with `copyText()`
Cursor Agent571ecea1bba3
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.tsindex f2ceba9a10..4d83cebfbb 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@@ -1,3 +1,4 @@+import {copyText} from '../../helpers/copy-text';import type {ComboboxValue} from '../NewComposition/ComboBox';import {showNotification} from '../Notifications/NotificationCenter';@@ -15,31 +16,27 @@ export const getCopyContextForAgentsMenuItem = ({leftItem: null,disabled: !contextForAgents,onClick: () => {- const pendingContext =- typeof contextForAgents === 'function'- ? contextForAgents()- : Promise.resolve(contextForAgents);+ if (!contextForAgents) {+ return;+ }- // Passing a pending Blob keeps the write tied to the click, which- // browsers require even if the context is resolved afterwards.- navigator.clipboard- .write([- new ClipboardItem({- 'text/plain': pendingContext.then((context) => {+ const copied =+ typeof contextForAgents === 'string'+ ? copyText(contextForAgents)+ : contextForAgents().then((context) => {if (!context) {throw new Error('No source location found');}- return new Blob([context], {type: 'text/plain'});- }),- }),- ])- .catch((err) => {- showNotification(- `Could not copy to clipboard: ${(err as Error).message}`,- 2000,- );- });+ return copyText(context);+ });++ copied.catch((err) => {+ showNotification(+ `Could not copy to clipboard: ${(err as Error).message}`,+ 2000,+ );+ });},quickSwitcherLabel: null,subMenu: null,diff --git a/packages/studio/src/test/sequence-context-menu-items.test.ts b/packages/studio/src/test/sequence-context-menu-items.test.tsindex 56da5baa87..fdf7b12221 100644--- a/packages/studio/src/test/sequence-context-menu-items.test.ts+++ b/packages/studio/src/test/sequence-context-menu-items.test.ts@@ -23,10 +23,6 @@ const originalNavigatorDescriptor = Object.getOwnPropertyDescriptor(globalThis,'navigator',);-const originalClipboardItemDescriptor = Object.getOwnPropertyDescriptor(- globalThis,- 'ClipboardItem',-);afterEach(() => {if (originalWindowDescriptor) {@@ -40,16 +36,6 @@ afterEach(() => {} else {Reflect.deleteProperty(globalThis, 'navigator');}-- if (originalClipboardItemDescriptor) {- Object.defineProperty(- globalThis,- 'ClipboardItem',- originalClipboardItemDescriptor,- );- } else {- Reflect.deleteProperty(globalThis, 'ClipboardItem');- }});const installTestWindow = () => {@@ -108,28 +94,14 @@ test('finds direct and nested elements that can copy a frame', () => {expect(findCopyableFrameElement(null)).toBeNull();});-test('copy context menu items write their agent context to the clipboard', async () => {- class TestClipboardItem {- readonly items: Record<string, Promise<Blob>>;-- constructor(items: Record<string, Promise<Blob>>) {- this.items = items;- }- }-- const copiedTexts: Promise<string>[] = [];- Object.defineProperty(globalThis, 'ClipboardItem', {- configurable: true,- value: TestClipboardItem,- });+test('copy context menu items write their agent context to the clipboard', () => {+ const copiedTexts: string[] = [];Object.defineProperty(globalThis, 'navigator', {configurable: true,value: {clipboard: {- write: (clipboardItems: TestClipboardItem[]) => {- copiedTexts.push(- clipboardItems[0].items['text/plain'].then((blob) => blob.text()),- );+ writeText: (text: string) => {+ copiedTexts.push(text);return Promise.resolve();},},@@ -144,9 +116,7 @@ test('copy context menu items write their agent context to the clipboard', async}item.onClick('copy-context-for-agents', null);- expect(await Promise.all(copiedTexts)).toEqual([- 'Property "style.opacity" in src/Video.tsx:10',- ]);+ expect(copiedTexts).toEqual(['Property "style.opacity" in src/Video.tsx:10']);});test('the file manager entry is only shown on macOS', () => {