Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(email): open Cc and Bcc from the keyboard in replies (#8140)

teod3f92d5c91c0
diff --git a/apps/web/src/features/email-compose/browser-test/playwright.app.config.ts b/apps/web/src/features/email-compose/browser-test/playwright.app.config.ts
new file mode 100644
index 0000000000..410f91b8ab
--- /dev/null
+++ b/apps/web/src/features/email-compose/browser-test/playwright.app.config.ts
@@ -0,0 +1,42 @@
+import { fileURLToPath } from 'node:url';
+import { defineConfig, devices } from '@playwright/test';
+
+const webDirectory = fileURLToPath(new URL('../../../../', import.meta.url));
+const port = process.env.EMAIL_COMPOSE_APP_BROWSER_PORT ?? '3048';
+
+/**
+ * Fixtures that mount the real composers, editor included, through the app's
+ * own Vite config. The default config's stubbed modules cannot serve them.
+ */
+export default defineConfig({
+ testDir: fileURLToPath(new URL('.', import.meta.url)),
+ testMatch: '*.app.e2e.ts',
+ outputDir: fileURLToPath(new URL('./test-results', import.meta.url)),
+ // The first page load on a fresh checkout pre-bundles the app's dependencies.
+ timeout: 240_000,
+ workers: 1,
+ reporter: 'line',
+ use: {
+ baseURL: `http://localhost:${port}`,
+ trace: 'retain-on-failure',
+ screenshot: 'only-on-failure',
+ },
+ webServer: {
+ command: `MACRO_DEV_HTTPS=false bunx vite --port ${port} --strictPort`,
+ cwd: webDirectory,
+ url: `http://localhost:${port}/app/`,
+ reuseExistingServer: true,
+ timeout: 90_000,
+ },
+ projects: [
+ {
+ name: 'chromium',
+ use: {
+ ...devices['Desktop Chrome'],
+ launchOptions: {
+ executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH,
+ },
+ },
+ },
+ ],
+});
diff --git a/apps/web/src/features/email-compose/browser-test/recipient-hotkeys-fixture.tsx b/apps/web/src/features/email-compose/browser-test/recipient-hotkeys-fixture.tsx
new file mode 100644
index 0000000000..8b213b11ca
--- /dev/null
+++ b/apps/web/src/features/email-compose/browser-test/recipient-hotkeys-fixture.tsx
@@ -0,0 +1,239 @@
+import '@app/index.css';
+import { AnalyticsContextProvider } from '@app/lib/analytics/analytics-context';
+import { PosthogProvider } from '@app/lib/analytics/posthog';
+import { ChannelsContextProvider } from '@core/context/channels';
+import { EmailLinksContextProvider } from '@core/context/emailLinks';
+import { QuickAccessProvider } from '@core/context/quickAccess/QuickAccessProvider';
+import { UserContextProvider } from '@core/context/user';
+import {
+ registerHotkey,
+ useHotKeyRoot,
+ useHotkeyDOMScope,
+} from '@core/hotkey/hotkeys';
+import { EntityProvider } from '@entity';
+import { QueryClient, QueryClientProvider } from '@tanstack/solid-query';
+import { createSignal, type JSX, onMount, Show } from 'solid-js';
+import { render } from 'solid-js/web';
+import { message } from '../../email-message/tests/messages';
+import type { EmailComposeContext } from '../context/compose-capabilities';
+import { ComposeProvider } from '../context/compose-context';
+import { EmailFormContextProvider } from '../context/email-form-context';
+import type { ReplyType } from '../core/reply-type';
+import { createEmailComposer } from '../primitives/email-composer';
+import { ComposeLayout } from '../views/compose-layout';
+import { ReplyInputView } from '../views/reply-input';
+
+const context: EmailComposeContext = {
+ drafts: {
+ saveDraft: async () => ({
+ draftId: 'draft',
+ threadId: 'thread',
+ inboxId: 'inbox',
+ }),
+ deleteDraft: async () => {},
+ restoreDraft: async () => {},
+ },
+ attachmentStorage: {
+ uploadAttachments: async () => {},
+ addForwardedAttachments: async () => {},
+ removeAttachment: async () => {},
+ removeForwardedAttachment: async () => {},
+ },
+ delivery: {
+ sendMessage: async () => ({ inboxId: 'inbox' }),
+ unschedule: async () => {},
+ schedule: async () => {},
+ archive: async () => {},
+ undoSend: async () => {},
+ },
+ draftLifecycle: {
+ observe: () => ({
+ state: () => undefined,
+ refresh: async () => undefined,
+ }),
+ },
+ notices: {
+ feedback: {
+ success: () => undefined,
+ failure: () => undefined,
+ alert: () => {},
+ dismiss: () => {},
+ },
+ blockingNotice: async () => {},
+ reportError: () => {},
+ },
+ accounts: {
+ inboxes: () => [
+ { id: 'inbox', email_address: '[email protected]', settings: {} },
+ ],
+ loading: () => false,
+ failed: () => false,
+ primaryId: () => 'inbox',
+ },
+ connectivity: { looksOffline: () => false },
+ presentation: {
+ viewerLoading: () => false,
+ onUpgrade: () => {},
+ prepareSignatureLinks: () => {},
+ isTouch: () => false,
+ isMobile: () => false,
+ scheduleEnabled: false,
+ signaturesEnabled: () => false,
+ },
+ editorFiles: {
+ readDroppedFiles: () => {},
+ makePublic: () => {},
+ uploadEditorFiles: () => {},
+ },
+ viewerEmail: () => '[email protected]',
+ recipients: () => [],
+ recipientName: (id) => id,
+ hasPaidAccess: () => true,
+ recordMention: () => {},
+};
+
+/**
+ * Production composers sit inside a split whose entity commands bind the same
+ * keys (Copy link, Copy branch name), so the composer has to claim them first.
+ */
+function ThreadScope(props: { children: JSX.Element }) {
+ const [attachHotkeys, scopeId] = useHotkeyDOMScope('fixture-thread');
+ const [threadCommand, setThreadCommand] = createSignal('none');
+ registerHotkey({
+ hotkey: 'shift+cmd+c',
+ scopeId,
+ description: 'Copy link',
+ keyDownHandler: () => {
+ setThreadCommand('Copy link');
+ return true;
+ },
+ runWithInputFocused: true,
+ });
+ registerHotkey({
+ hotkey: 'shift+cmd+b',
+ scopeId,
+ description: 'Copy branch name',
+ keyDownHandler: () => {
+ setThreadCommand('Copy branch name');
+ return true;
+ },
+ runWithInputFocused: true,
+ });
+ let element!: HTMLDivElement;
+ onMount(() => attachHotkeys(element));
+ return (
+ <div ref={element}>
+ {props.children}
+ <output data-testid="thread-command">{threadCommand()}</output>
+ </div>
+ );
+}
+
+function NewEmail() {
+ const state = createEmailComposer({
+ ...context,
+ initialTo: ['[email protected]'],
+ });
+ return (
+ <ComposeProvider
+ value={{
+ ...state.context,
+ bodyActions: {
+ recipientAdded: () => {},
+ readDroppedFiles: () => {},
+ insertFiles: () => {},
+ },
+ isMobile: () => false,
+ scheduleEnabled: false,
+ attachmentFailure: () => {},
+ }}
+ >
+ <ComposeLayout />
+ </ComposeProvider>
+ );
+}
+
+function Reply(props: { replyType: ReplyType }) {
+ const parent = message('parent', {
+ from: { email: '[email protected]' },
+ to: [{ email: '[email protected]' }, { email: '[email protected]' }],
+ });
+ const [requestedType, setRequestedType] = createSignal<ReplyType | undefined>(
+ props.replyType
+ );
+ return (
+ <EmailFormContextProvider
+ context={{
+ viewerEmail: context.viewerEmail,
+ inboxes: context.accounts.inboxes,
+ }}
+ formOptions={{
+ getMessageById: () => parent,
+ getDraftForMessageReply: () => undefined,
+ }}
+ >
+ <ReplyInputView
+ context={context}
+ sourceEntityId="thread"
+ replyingTo={() => parent}
+ session={{
+ thread: () => ({
+ db_id: 'thread',
+ link_id: 'inbox',
+ inbox_visible: true,
+ }),
+ recipientOptions: () => [],
+ isPersonalReply: () => false,
+ onDraftRemoved: () => {},
+ exitToThread: () => false,
+ replyRequest: {
+ replyType: requestedType,
+ clear: () => setRequestedType(undefined),
+ },
+ }}
+ />
+ </EmailFormContextProvider>
+ );
+}
+
+const replyTypes: ReplyType[] = ['reply', 'reply-all', 'forward'];
+
+/**
+ * The real new-email layout and reply input, driven by the real hotkey root.
+ * The editor menus and recipient fields read the app shell's providers, in
+ * the order `routes/Root.tsx` mounts them.
+ */
+function Fixture() {
+ useHotKeyRoot();
+ const composer = new URLSearchParams(location.search).get('composer');
+ const replyType = replyTypes.find((type) => type === composer);
+ return (
+ <QueryClientProvider client={new QueryClient()}>
+ <AnalyticsContextProvider>
+ <PosthogProvider>
+ <EntityProvider>
+ <UserContextProvider>
+ <EmailLinksContextProvider>
+ <ChannelsContextProvider>
+ <QuickAccessProvider>
+ <main class="min-h-screen bg-surface p-4 text-ink">
+ <ThreadScope>
+ <Show when={replyType} fallback={<NewEmail />}>
+ {(type) => <Reply replyType={type()} />}
+ </Show>
+ </ThreadScope>
+ </main>
+ </QuickAccessProvider>
+ </ChannelsContextProvider>
+ </EmailLinksContextProvider>
+ </UserContextProvider>
+ </EntityProvider>
+ </PosthogProvider>
+ </AnalyticsContextProvider>
+ </QueryClientProvider>
+ );
+}
+
+const root = document.getElementById('root');
+if (!root) throw new Error('Fixture root missing');
+render(() => <Fixture />, root);
diff --git a/apps/web/src/features/email-compose/browser-test/recipient-hotkeys.app.e2e.ts b/apps/web/src/features/email-compose/browser-test/recipient-hotkeys.app.e2e.ts
new file mode 100644
index 0000000000..0207f95026
--- /dev/null
+++ b/apps/web/src/features/email-compose/browser-test/recipient-hotkeys.app.e2e.ts
@@ -0,0 +1,38 @@
+import { expect, test } from '@playwright/test';
+
+test.beforeEach(async ({ page }) => {
+ // The fixture's providers would otherwise reach the hosted dev backend.
+ await page.routeWebSocket('**', (socket) => socket.close());
+ await page.route('**/__macro_dev/**', (route) => route.abort());
+ await page.route('https://**', (route) => route.abort());
+});
+
+for (const composer of ['new', 'reply', 'reply-all', 'forward']) {
+ test(`Cmd+Shift+C and Cmd+Shift+B open Cc and Bcc in the ${composer} composer`, async ({
+ page,
+ }) => {
+ await page.goto(
+ `/src/features/email-compose/browser-test/recipient-hotkeys.html?composer=${composer}`
+ );
+ await page.locator('[contenteditable="true"]').click();
+
+ await page.keyboard.press('ControlOrMeta+Shift+C');
+ const cc = page
+ .getByText('Cc', { exact: true })
+ .locator('..')
+ .getByRole('combobox');
+ await expect(cc).toBeFocused();
+
+ await page.keyboard.press('ControlOrMeta+Shift+B');
+ const bcc = page
+ .getByText('Bcc', { exact: true })
+ .locator('..')
+ .getByRole('combobox');
+ await expect(bcc).toBeFocused();
+
+ // Once the field is visible the shortcut only moves focus back to it.
+ await page.keyboard.press('ControlOrMeta+Shift+C');
+ await expect(cc).toBeFocused();
+ await expect(page.getByTestId('thread-command')).toHaveText('none');
+ });
+}
diff --git a/apps/web/src/features/email-compose/browser-test/recipient-hotkeys.html b/apps/web/src/features/email-compose/browser-test/recipient-hotkeys.html
new file mode 100644
index 0000000000..fb894f28d6
--- /dev/null
+++ b/apps/web/src/features/email-compose/browser-test/recipient-hotkeys.html
@@ -0,0 +1 @@
+<!doctype html><html><head><meta charset="UTF-8" /><title>Composer recipient hotkeys fixture</title></head><body><div id="root"></div><script type="module" src="./recipient-hotkeys-fixture.tsx"></script></body></html>
diff --git a/apps/web/src/features/email-compose/primitives/cc-bcc-hotkeys.ts b/apps/web/src/features/email-compose/primitives/cc-bcc-hotkeys.ts
new file mode 100644
index 0000000000..7041061114
--- /dev/null
+++ b/apps/web/src/features/email-compose/primitives/cc-bcc-hotkeys.ts
@@ -0,0 +1,46 @@
+import { registerHotkey } from '@core/hotkey/hotkeys';
+import { TOKENS } from '@core/hotkey/tokens';
+import type { Accessor } from 'solid-js';
+
+type RecipientField = {
+ reveal: () => void;
+ input: () => HTMLElement | undefined;
+};
+
+/**
+ * Cmd+Shift+C and Cmd+Shift+B reveal and focus the Cc and Bcc fields. Each
+ * composer registers them on its own scope, because the enclosing split binds
+ * the same keys to Copy link and Copy branch name.
+ */
+export function registerCcBccHotkeys(options: {
+ scopeId: string;
+ disabled: Accessor<boolean>;
+ cc: RecipientField;
+ bcc: RecipientField;
+}) {
+ const edit = (field: RecipientField) => () => {
+ if (options.disabled()) return false;
+ field.reveal();
+ // The field mounts on reveal; focus it once its input ref is set.
+ queueMicrotask(() => field.input()?.focus());
+ return true;
+ };
+ registerHotkey({
+ hotkey: 'shift+cmd+c',
+ scopeId: options.scopeId,
+ description: 'Edit "Cc" recipients',
+ keyDownHandler: edit(options.cc),
+ runWithInputFocused: true,
+ hotkeyToken: TOKENS.email.compose.edit.ccRecipients,
+ shouldReturnFocusOnClose: false,
+ });
+ registerHotkey({
+ hotkey: 'shift+cmd+b',
+ scopeId: options.scopeId,
+ description: 'Edit "Bcc" recipients',
+ keyDownHandler: edit(options.bcc),
+ runWithInputFocused: true,
+ hotkeyToken: TOKENS.email.compose.edit.bccRecipients,
+ shouldReturnFocusOnClose: false,
+ });
+}
diff --git a/apps/web/src/features/email-compose/views/compose-layout.tsx b/apps/web/src/features/email-compose/views/compose-layout.tsx
index 0ba0e46487..adcc324ce7 100644
--- a/apps/web/src/features/email-compose/views/compose-layout.tsx
+++ b/apps/web/src/features/email-compose/views/compose-layout.tsx
@@ -14,6 +14,7 @@ import {
import { Dynamic } from 'solid-js/web';
import { FromInboxSelector } from '../components/from-inbox-selector';
import { useCompose } from '../context/compose-context';
+import { registerCcBccHotkeys } from '../primitives/cc-bcc-hotkeys';
import { ComposeBody } from './compose-body';
import { ComposeRecipients } from './compose-recipients';
import { ComposeSubject } from './compose-subject';
@@ -92,42 +93,17 @@ export function ComposeLayout(props: {
shouldReturnFocusOnClose: false,
});
- registerHotkey({
- hotkey: 'shift+cmd+c',
+ registerCcBccHotkeys({
scopeId: composeHotkeyScope,
- description: 'Edit "Cc" recipients',
- keyDownHandler: () => {
- if (ctx.disabled()) return false;
- if (!showCc()) {
- setShowCc(true);
- queueMicrotask(() => refs()?.ccRecipientsSelector?.focus());
- return true;
- }
- refs()?.ccRecipientsSelector?.focus();
- return true;
+ disabled: ctx.disabled,
+ cc: {
+ reveal: () => setShowCc(true),
+ input: () => refs().ccRecipientsSelector,
},
- runWithInputFocused: true,
- hotkeyToken: TOKENS.email.compose.edit.ccRecipients,
- shouldReturnFocusOnClose: false,
- });
-
- registerHotkey({
- hotkey: 'shift+cmd+b',
- scopeId: composeHotkeyScope,
- description: 'Edit "Bcc" recipients',
- keyDownHandler: () => {
- if (ctx.disabled()) return false;
- if (!showBcc()) {
- setShowBcc(true);
- queueMicrotask(() => refs()?.bccRecipientsSelector?.focus());
- return true;
- }
- refs()?.bccRecipientsSelector?.focus();
- return true;
+ bcc: {
+ reveal: () => setShowBcc(true),
+ input: () => refs().bccRecipientsSelector,
},
- runWithInputFocused: true,
- hotkeyToken: TOKENS.email.compose.edit.bccRecipients,
- shouldReturnFocusOnClose: false,
});
registerHotkey({
diff --git a/apps/web/src/features/email-compose/views/reply-input.tsx b/apps/web/src/features/email-compose/views/reply-input.tsx
index 938cf27098..dc139a6da7 100644
--- a/apps/web/src/features/email-compose/views/reply-input.tsx
+++ b/apps/web/src/features/email-compose/views/reply-input.tsx
@@ -33,6 +33,7 @@ import type { EmailComposeContext } from '../context/compose-capabilities';
import { getOrInitEmailFormContext } from '../context/email-form-context';
import { decodeBase64Utf8 } from '../core/decode-base64';
import { plainTextToHtml } from '../core/plain-text-to-html';
+import { registerCcBccHotkeys } from '../primitives/cc-bcc-hotkeys';
import { createDraftSyncStatus } from '../primitives/draft-sync-status';
import { registerToggleAppendedThread } from '../primitives/prepare-email-body';
import { ReplyEnvelope } from './reply-envelope';
@@ -280,6 +281,26 @@ function LoadedReplyInputView(props: ReplyInputViewProps) {
displayPriority: 10,
});
+ const recipients = state.recipients;
+ registerCcBccHotkeys({
+ scopeId: composeHotkeyScope,
+ disabled: recipients.disabled,
+ cc: {
+ reveal: () => {
+ recipients.setShowExpandedRecipients(true);
+ recipients.setShowCc(true);
+ },
+ input: recipients.ccRef,
+ },
+ bcc: {
+ reveal: () => {
+ recipients.setShowExpandedRecipients(true);
+ recipients.setShowBcc(true);
+ },
+ input: recipients.bccRef,
+ },
+ });
+
registerHotkey({
hotkey: 'arrowup',
scopeId: composeHotkeyScope,
diff --git a/docs/agent-guide/email.md b/docs/agent-guide/email.md
index fb2f5ada96..d15fc6360c 100644
--- a/docs/agent-guide/email.md
+++ b/docs/agent-guide/email.md
@@ -299,6 +299,12 @@ Standalone compose uses one right-aligned row inside its 16px content padding:
delete, attach, format, schedule, and send. Touch compose uses its header toolbar.
`R` and `Alt+R` (`Option+R` on macOS) open reply-all for the selected message,
or the latest message when none is selected. `F` opens a forward and focuses To.
+In new emails, replies, reply-alls, and forwards, `Cmd+Shift+C` (`Ctrl+Shift+C`)
+reveals and focuses Cc and `Cmd+Shift+B` does the same for Bcc, expanding a
+collapsed reply header; inside a composer they never fall through to the
+thread's Copy link. `bunx playwright test --config
+src/features/email-compose/browser-test/playwright.app.config.ts` (from
+`apps/web`) checks both shortcuts in all four composers.
While an editable field is focused, Escape is handled by that field before the
close-reply shortcut.
An edited reply remains a draft when navigating away and returning. Standalone