Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(email): add mail-client keys for drafts, threads, star, undo, search, tabs (#8231)
teod20af7eeb235
diff --git a/apps/web/src/components/app/app-sidebar/sidebar.tsx b/apps/web/src/components/app/app-sidebar/sidebar.tsxindex d5fad4dfc5..fafc744960 100644--- a/apps/web/src/components/app/app-sidebar/sidebar.tsx+++ b/apps/web/src/components/app/app-sidebar/sidebar.tsx@@ -29,6 +29,7 @@ import {enableTasksReviews,isFeatureEnabled,} from '@core/constant/featureFlags';+import { getRunnableHotkeys } from '@core/hotkey/getCommands';import { registerHotkey } from '@core/hotkey/hotkeys';import { clearPressedKeys } from '@core/hotkey/state';import { type HotkeyToken, TOKENS } from '@core/hotkey/tokens';@@ -261,9 +262,6 @@ export const GoToHotkeys = () => {leaderHotkey.dispose();});- const registeredGoToKeys = () =>- new Set<ValidHotkey>(links().flatMap((link) => link.hotkey ?? []));-// When the go to command scope is active, we want to prevent// other default hotkeys from running. So doing "g" + some key// not part of the sidebar hotkeys, won't fire the command@@ -281,7 +279,8 @@ export const GoToHotkeys = () => {if (context.activeScopeId !== GO_TO_COMMAND_SCOPE ||- registeredGoToKeys().has(context.pressedKeysString)+ // The sidebar's letters and those a focused view adds (Email's g s).+ getRunnableHotkeys(GO_TO_COMMAND_SCOPE).has(context.pressedKeysString)) {return false;}@@ -336,6 +335,9 @@ export const GoToHotkeys = () => {description: `Go to ${link.label}`,keyDownHandler: openSidebarView,icon: link.icon,+ // Views can claim a letter while focused (Email's g then i). Re-running+ // this effect when flags load must not eclipse those.+ registrationType: 'add',});});diff --git a/apps/web/src/components/list/use-list-interactions.ts b/apps/web/src/components/list/use-list-interactions.tsindex 613848af86..fa1ea0ece4 100644--- a/apps/web/src/components/list/use-list-interactions.ts+++ b/apps/web/src/components/list/use-list-interactions.ts@@ -290,7 +290,7 @@ export function useListInteractions<TItem, TMetadata = unknown>(}).withGroup(group);registerHotkey({- hotkey: 'home',+ hotkey: ['home', 'cmd+arrowup'],hotkeyToken: TOKENS.entity.jump.home,scopeId: options.scopeId,description: 'Go to first item',@@ -311,7 +311,7 @@ export function useListInteractions<TItem, TMetadata = unknown>(}).withGroup(group);registerHotkey({- hotkey: ['end', 'shift+g'],+ hotkey: ['end', 'shift+g', 'cmd+arrowdown'],hotkeyToken: TOKENS.entity.jump.end,scopeId: options.scopeId,description: 'Go to last item',diff --git a/apps/web/src/features/block-email/component/Block.tsx b/apps/web/src/features/block-email/component/Block.tsxindex 994a2840dc..50ed463f1d 100644--- a/apps/web/src/features/block-email/component/Block.tsx+++ b/apps/web/src/features/block-email/component/Block.tsx@@ -6,6 +6,7 @@ import { useGlobalNotificationSource } from '@components/app/GlobalAppState';import { useBlockId } from '@core/block';import { DocumentBlockContainer } from '@core/component/DocumentBlockContainer';import { toEntityLoadError } from '@core/component/EntityLoadGate';+import { TOKENS } from '@core/hotkey/tokens';import { fireAndForget } from '@core/util/fireAndForget';import { buildEntityData } from '@entity';import { useThreadQuery } from '@queries/email/thread';@@ -44,7 +45,11 @@ export default function BlockEmail() {});});- useBlockEntityCommands({ resolveEntity: commandEntity });+ useBlockEntityCommands({+ resolveEntity: commandEntity,+ extraFavoriteHotkey: { hotkey: 's', hotkeyToken: TOKENS.email.star },+ extraMuteHotkey: { hotkey: 'shift+m', hotkeyToken: TOKENS.email.mute },+ });// The gate owns the load policy: structural errors are authoritative even// over cached data, a transport failure over cached data still renders thediff --git a/apps/web/src/features/block-email/util/emailHotkeys.ts b/apps/web/src/features/block-email/util/emailHotkeys.tsindex 23780ec871..5f7c5bccff 100644--- a/apps/web/src/features/block-email/util/emailHotkeys.ts+++ b/apps/web/src/features/block-email/util/emailHotkeys.ts@@ -94,17 +94,34 @@ export function registerEmailHotkeys(displayPriority: 5,});registerHotkey({- hotkey: 'arrowup',+ hotkey: ['arrowup', 'p'],scopeId,description: 'Previous message',keyDownHandler: handlers.navigateToPreviousMessage,hotkeyToken: TOKENS.email.previousMessage,});registerHotkey({- hotkey: 'arrowdown',+ hotkey: ['arrowdown', 'n'],scopeId,description: 'Next message',keyDownHandler: handlers.navigateToNextMessage,hotkeyToken: TOKENS.email.nextMessage,});++ registerHotkey({+ hotkey: 'o',+ scopeId,+ description: 'Expand or collapse message',+ keyDownHandler: handlers.expandFocusedMessage,+ hotkeyToken: TOKENS.email.expandMessage,+ displayPriority: 6,+ });+ registerHotkey({+ hotkey: 'shift+o',+ scopeId,+ description: 'Expand all messages',+ keyDownHandler: handlers.expandAllMessages,+ hotkeyToken: TOKENS.email.expandAllMessages,+ displayPriority: 6,+ });}diff --git a/apps/web/src/features/command/CommandItem.tsx b/apps/web/src/features/command/CommandItem.tsxindex c1e162015e..e91248f793 100644--- a/apps/web/src/features/command/CommandItem.tsx+++ b/apps/web/src/features/command/CommandItem.tsx@@ -51,9 +51,10 @@ function CommandItemHotkey(props: { item: CommandMenuItem }) {};const hasHotkey = () =>- hasValidHotkey(token()) ||- Boolean(shortcut()) ||- Boolean(sequence()?.length);+ !commandItem()?.hideHotkey &&+ (hasValidHotkey(token()) ||+ Boolean(shortcut()) ||+ Boolean(sequence()?.length));const StepHotkey = (step: DisplayHotkeyStep) => (<div class="p-2 py-0.5 border border-edge-muted rounded-md">diff --git a/apps/web/src/features/command/useCommandItems.test.ts b/apps/web/src/features/command/useCommandItems.test.tsindex b41e64c2fe..4808323c17 100644--- a/apps/web/src/features/command/useCommandItems.test.ts+++ b/apps/web/src/features/command/useCommandItems.test.ts@@ -16,6 +16,7 @@ const mocks = vi.hoisted(() => ({requestedBuckets: [] as Bucket[],entityMode: (): boolean => false,scope: (): CommandWithInfo[] => [],+ goTo: [] as CommandWithInfo[],}));// These tests exercise entity loading independently of Projects and its providers.vi.mock('@app/lib/analytics/posthog', () => ({@@ -50,7 +51,7 @@ vi.mock('@core/context/quickAccess', () => ({vi.mock('@core/hotkey/getCommands', () => ({getActiveCommandsFromScope: (scope: string) =>scope === 'go-to'- ? []+ ? mocks.goTo: [{scopeId: 'global',@@ -76,6 +77,7 @@ vi.mock('./state', () => ({let dispose: (() => void) | undefined;afterEach(() => {dispose?.();+ mocks.goTo = [];});function setup() {return createRoot((cleanup) => {@@ -237,3 +239,39 @@ it('keeps desktop All email-free while mobile composes emails without desktop cocleanup();});});++describe('command menu go-to sequences', () => {+ it('shows a letter on the command it runs when a focused view claims it', () => {+ const goTo = (+ description: string,+ handlerPriority?: CommandWithInfo['handlerPriority']+ ) => ({+ scopeId: 'go-to',+ description,+ hotkeys: ['t' as const],+ handlerPriority,+ runWithInputFocused: false,+ scopeLevel: 0,+ hotkeyIsShadowed: false,+ });+ mocks.goTo = [goTo('Go to Tasks'), goTo('Go to Sent', 3)];+ const { result } = setup();++ const item = (description: string) => {+ const found = result+ .items()+ .find(+ (item) =>+ item.kind === 'command' && item.data.description === description+ );+ return found?.kind === 'command' ? found : undefined;+ };+ expect(item('Go to Sent')?.displayHotkeySequence).toEqual([+ { shortcut: 'g' },+ { shortcut: 't' },+ ]);+ expect(item('Go to Sent')?.hideHotkey).toBe(false);+ expect(item('Go to Tasks')?.displayHotkeySequence).toBeUndefined();+ expect(item('Go to Tasks')?.hideHotkey).toBe(true);+ });+});diff --git a/apps/web/src/features/command/useCommandItems.ts b/apps/web/src/features/command/useCommandItems.tsindex 92f4f3e4b4..b398a63a72 100644--- a/apps/web/src/features/command/useCommandItems.ts+++ b/apps/web/src/features/command/useCommandItems.ts@@ -13,7 +13,7 @@ import {} from '@core/hotkey/getCommands';import { activeScope, hotkeyScopeTree } from '@core/hotkey/state';import { TOKENS } from '@core/hotkey/tokens';-import type { HotkeyCommand } from '@core/hotkey/types';+import type { HotkeyCommand, ValidHotkey } from '@core/hotkey/types';import type { TimestampedItem } from '@core/util/freshSort';import { mergeSortedArrays } from '@core/util/list';import type { CrmContactEntity } from '@entity';@@ -39,6 +39,8 @@ type CommandItem = {data: HotkeyCommand;displayHotkey?: string;displayHotkeySequence?: DisplayHotkeyStep[];+ /** Its keys run another command here, as Email's g t runs Sent. */+ hideHotkey?: boolean;};/** Search item: triggers full-text search in the sidebar Search view */@@ -153,6 +155,7 @@ function commandsToItems(displayHotkeySequence?: (command: CommandWithInfo) => DisplayHotkeyStep[] | undefined;+ hideHotkey?: (command: CommandWithInfo) => boolean;}): CommandItem[] {const seen = new Set<string>();@@ -189,6 +192,7 @@ function commandsToItems(data: command,displayHotkey: options?.displayHotkey?.(command),displayHotkeySequence: options?.displayHotkeySequence?.(command),+ hideHotkey: options?.hideHotkey?.(command),};});@@ -278,6 +282,18 @@ function useCommandsList(limitToCurrentScope: true,ignoreInputFocused: true,});+ // The command each go-to letter runs: a focused view's letter (Email's g t+ // Sent) runs before the app's, which then shows no keys.+ const goToKeyOwners = new Map<ValidHotkey, CommandWithInfo>();+ for (const command of [...goToCommands].sort(+ (a, b) => (b.handlerPriority ?? 0) - (a.handlerPriority ?? 0)+ )) {+ for (const hotkey of command.hotkeys ?? []) {+ if (!goToKeyOwners.has(hotkey)) goToKeyOwners.set(hotkey, command);+ }+ }+ const ownGoToKey = (command: CommandWithInfo) =>+ command.hotkeys?.find((key) => goToKeyOwners.get(key) === command);return createMemo(() => {projectsFlag();@@ -320,11 +336,13 @@ function useCommandsList(),...availableItems(goToCommands, {displayHotkeySequence: (command) => {- const hotkey = command.hotkeys?.[0];+ const hotkey = ownGoToKey(command);return hotkey? [{ shortcut: GO_TO_LEADER_KEY }, { shortcut: hotkey }]: undefined;},+ hideHotkey: (command) =>+ Boolean(command.hotkeys?.length) && !ownGoToKey(command),}),];});diff --git a/apps/web/src/features/email-compose/primitives/draft-action-hotkeys.ts b/apps/web/src/features/email-compose/primitives/draft-action-hotkeys.tsnew file mode 100644index 0000000000..4350f67749--- /dev/null+++ b/apps/web/src/features/email-compose/primitives/draft-action-hotkeys.ts@@ -0,0 +1,48 @@+import { registerHotkey } from '@core/hotkey/hotkeys';+import { TOKENS } from '@core/hotkey/tokens';+import { openFilePicker } from '@core/util/filePicker';+import type { Accessor } from 'solid-js';++/**+ * Mail-client draft shortcuts. Cmd+Shift+. and Cmd+Shift+, (Superhuman) and+ * Cmd+Shift+D (Gmail) discard the draft; Cmd+Shift+U attaches files. Each+ * composer registers them on its own scope so a reply and a standalone draft+ * act only on themselves.+ */+export function registerDraftActionHotkeys(options: {+ scopeId: string;+ disabled: Accessor<boolean>;+ discard: () => void;+ /** Omit when the composer takes no attachments. */+ attach?: (files: File[]) => void;+}) {+ registerHotkey({+ hotkey: ['shift+cmd+.', 'shift+cmd+,', 'shift+cmd+d'],+ scopeId: options.scopeId,+ description: 'Discard draft',+ keyDownHandler: () => {+ if (options.disabled()) return false;+ options.discard();+ return true;+ },+ runWithInputFocused: true,+ hotkeyToken: TOKENS.email.discardDraft,+ shouldReturnFocusOnClose: false,+ });++ const attach = options.attach;+ if (!attach) return;+ registerHotkey({+ hotkey: 'shift+cmd+u',+ scopeId: options.scopeId,+ description: 'Attach files',+ keyDownHandler: () => {+ if (options.disabled()) return false;+ openFilePicker({ multiple: true }, attach);+ return true;+ },+ runWithInputFocused: true,+ hotkeyToken: TOKENS.email.attach,+ shouldReturnFocusOnClose: false,+ });+}diff --git a/apps/web/src/features/email-compose/primitives/format-shortcuts.ts b/apps/web/src/features/email-compose/primitives/format-shortcuts.tsnew file mode 100644index 0000000000..7930649998--- /dev/null+++ b/apps/web/src/features/email-compose/primitives/format-shortcuts.ts@@ -0,0 +1,14 @@+import {+ DefaultShortcuts,+ ListAndQuoteShortcuts,+} from '@core/component/LexicalMarkdown/plugins/keyboard-shortcuts';++/**+ * Formatting keys for the email editors: the inline formats the floating menu+ * advertises (strikethrough, code, highlight) plus the mail-client list and+ * quote keys, Cmd+Shift+7/8/9.+ */+export const EMAIL_FORMAT_SHORTCUTS = [+ ...DefaultShortcuts,+ ...ListAndQuoteShortcuts,+];diff --git a/apps/web/src/features/email-compose/views/compose-body.tsx b/apps/web/src/features/email-compose/views/compose-body.tsxindex 1ed31d8861..810c44f45b 100644--- a/apps/web/src/features/email-compose/views/compose-body.tsx+++ b/apps/web/src/features/email-compose/views/compose-body.tsx@@ -2,6 +2,7 @@ import { EmailAttachmentPill } from '@app/features/email-message/components/attaimport { useMacroMentionLinkResolver } from '@components/app/split-layout/split-router/mention-links';import { FileDropOverlay } from '@core/component/FileDropOverlay';import { MarkdownTextarea } from '@core/component/LexicalMarkdown/component/core/MarkdownTextarea';+import { keyboardShortcutsPlugin } from '@core/component/LexicalMarkdown/plugins/keyboard-shortcuts';import { isInlineMediaFileName } from '@core/component/LexicalMarkdown/utils/fileUploadUtils';import { fileFolderDrop } from '@core/directive/fileFolderDrop';import { Telemetry } from '@macro-inc/observability';@@ -22,6 +23,7 @@ import { createAttachmentViewer } from '../components/attachment-viewer';import { MacroSignatureButton } from '../components/macro-signature-button';import { useCompose } from '../context/compose-context';import type { DraftFormAttachment } from '../primitives/email-form-state';+import { EMAIL_FORMAT_SHORTCUTS } from '../primitives/format-shortcuts';import { addUserMentionToCc } from '../primitives/mention-to-cc';false && fileFolderDrop;@@ -49,11 +51,17 @@ export function ComposeBody(props: {});};+ let unregisterFormatShortcuts: (() => void) | undefined;const captureEditor = (ed: LexicalEditor) => {logComposeBody('captureEditor called');setEditor(ed);ctx.captureEditor(ed);+ unregisterFormatShortcuts?.();+ unregisterFormatShortcuts = keyboardShortcutsPlugin({+ shortcuts: EMAIL_FORMAT_SHORTCUTS,+ })(ed);};+ onCleanup(() => unregisterFormatShortcuts?.());logComposeBody('mounted', {initialHtmlLength: ctx.initialHtml()?.length ?? 0,diff --git a/apps/web/src/features/email-compose/views/compose-layout.tsx b/apps/web/src/features/email-compose/views/compose-layout.tsxindex 175575ae77..8c7e48decc 100644--- a/apps/web/src/features/email-compose/views/compose-layout.tsx+++ b/apps/web/src/features/email-compose/views/compose-layout.tsx@@ -15,6 +15,7 @@ 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 { registerDraftActionHotkeys } from '../primitives/draft-action-hotkeys';import { ComposeBody } from './compose-body';import { ComposeRecipients } from './compose-recipients';import { ComposeSubject } from './compose-subject';@@ -134,6 +135,13 @@ export function ComposeLayout(props: {shouldReturnFocusOnClose: false,});+ registerDraftActionHotkeys({+ scopeId: composeHotkeyScope,+ disabled: ctx.disabled,+ discard: () => ctx.onDelete?.(),+ attach: ctx.hideAttachments ? undefined : ctx.onAddAttachments,+ });+registerHotkey({hotkey: 'cmd+enter',scopeId: composeHotkeyScope,diff --git a/apps/web/src/features/email-compose/views/reply-input.tsx b/apps/web/src/features/email-compose/views/reply-input.tsxindex 5b082ec301..259853ebe2 100644--- a/apps/web/src/features/email-compose/views/reply-input.tsx+++ b/apps/web/src/features/email-compose/views/reply-input.tsx@@ -4,6 +4,7 @@ import { FileDropOverlay } from '@core/component/FileDropOverlay';import { buildConfig } from '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder';import { MarkdownShell } from '@core/component/LexicalMarkdown/builder/MarkdownShell';import { iosCursorScrollPlugin } from '@core/component/LexicalMarkdown/plugins/ios-cursor-scroll';+import { keyboardShortcutsPlugin } from '@core/component/LexicalMarkdown/plugins/keyboard-shortcuts';import { fileFolderDrop } from '@core/directive/fileFolderDrop';import { fileSelector } from '@core/directive/fileSelector';import { registerHotkey, useHotkeyDOMScope } from '@core/hotkey/hotkeys';@@ -43,7 +44,9 @@ 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 { registerDraftActionHotkeys } from '../primitives/draft-action-hotkeys';import { createDraftSyncStatus } from '../primitives/draft-sync-status';+import { EMAIL_FORMAT_SHORTCUTS } from '../primitives/format-shortcuts';import { registerToggleAppendedThread } from '../primitives/prepare-email-body';import { ReplyEnvelope } from './reply-envelope';@@ -263,6 +266,7 @@ function LoadedReplyInputView(props: ReplyInputViewProps) {.withRestoreFocus().withSelectionData().withFloatingFormatMenu()+ .use(keyboardShortcutsPlugin({ shortcuts: EMAIL_FORMAT_SHORTCUTS })).use(registerToggleAppendedThread).onChange(state.onContentChange).withFilePaste({@@ -323,6 +327,13 @@ function LoadedReplyInputView(props: ReplyInputViewProps) {displayPriority: 10,});+ registerDraftActionHotkeys({+ scopeId: composeHotkeyScope,+ disabled: editingDisabled,+ discard: () => fireAndForget(deleteDraftAndReset(), 'email-compose'),+ attach: handleAddAttachments,+ });+const recipients = state.recipients;registerCcBccHotkeys({scopeId: composeHotkeyScope,diff --git a/apps/web/src/features/email-thread/core/thread-keyboard.ts b/apps/web/src/features/email-thread/core/thread-keyboard.tsindex 214537989a..9fce776e51 100644--- a/apps/web/src/features/email-thread/core/thread-keyboard.ts+++ b/apps/web/src/features/email-thread/core/thread-keyboard.ts@@ -21,4 +21,7 @@ export interface EmailThreadKeyboardHandlers {markSenderNoise: () => boolean;navigateToPreviousMessage: () => boolean;navigateToNextMessage: () => boolean;+ /** Expands the focused message, or collapses it if already expanded. */+ expandFocusedMessage: () => boolean;+ expandAllMessages: () => boolean;}diff --git a/apps/web/src/features/email-thread/primitives/thread-navigation.test.ts b/apps/web/src/features/email-thread/primitives/thread-navigation.test.tsindex 7808663fc1..526d85cc4d 100644--- a/apps/web/src/features/email-thread/primitives/thread-navigation.test.ts+++ b/apps/web/src/features/email-thread/primitives/thread-navigation.test.ts@@ -175,3 +175,40 @@ it('retains Enter activation of the focused hidden-message button', () => {state.dispose();}});++it('o toggles the focused message open and closed, defaulting to the latest', () => {+ const state = navigationWithList(['first', 'last']);+ const handlers = state.handlers();+ const expanded = (id: string) => state.context.messages.expandedBodyIds[id];+ try {+ // The latest message starts open, so 'o' with nothing focused closes it.+ expect(handlers?.expandFocusedMessage()).toBe(true);+ expect(expanded('last')).toBe(false);++ state.context.messages.setFocused('first');+ expect(handlers?.expandFocusedMessage()).toBe(true);+ expect(expanded('first')).toBe(true);+ expect(handlers?.expandFocusedMessage()).toBe(true);+ expect(expanded('first')).toBe(false);++ state.setSnapshot(thread([]));+ expect(handlers?.expandFocusedMessage()).toBe(false);+ } finally {+ state.dispose();+ }+});++it('shift+o opens every message, including the collapsed middle run', () => {+ const ids = ['a', 'b', 'c', 'd', 'e'];+ const state = navigationWithList(ids);+ try {+ expect(state.navigation.showMiddleMessages()).toBe(false);+ expect(state.handlers()?.expandAllMessages()).toBe(true);+ expect(state.navigation.showMiddleMessages()).toBe(true);+ for (const id of ids) {+ expect(state.context.messages.expandedBodyIds[id]).toBe(true);+ }+ } finally {+ state.dispose();+ }+});diff --git a/apps/web/src/features/email-thread/primitives/thread-navigation.ts b/apps/web/src/features/email-thread/primitives/thread-navigation.tsindex a704bf1cc3..3f90e21735 100644--- a/apps/web/src/features/email-thread/primitives/thread-navigation.ts+++ b/apps/web/src/features/email-thread/primitives/thread-navigation.ts@@ -595,6 +595,37 @@ export function createThreadNavigation(return true;};const markDone = () => context.archiveThreadAndAdvance();++ /** 'o' toggles the focused (or last) message open or closed. */+ const expandFocusedMessage = () => {+ const target = getHotkeyTarget();+ const messageId = target?.message.db_id;+ if (!target || !messageId) return false;+ const expand = !isMessageRenderedExpanded(target);+ context.messages.setExpandedBodyId(messageId, expand);+ if (expand) {+ revealMessageAfterLayout(+ messageId,+ untrack(context.messages.list),+ untrack(context.messagesListRef)+ );+ }+ return true;+ };++ /** 'shift+o' opens every message, including the collapsed middle run. */+ const expandAllMessages = () => {+ const messages = context.messages.list();+ if (messages.length === 0) return false;+ setUserOpenedMiddle(true);+ if (context.messages.hiddenChipFocused()) leaveHiddenChip();+ for (const message of messages) {+ if (message.db_id)+ context.messages.setExpandedBodyId(message.db_id, true);+ }+ return true;+ };+onMount(() =>host.registerKeyboard?.({replyToFocusedMessage: () => openHotkeyTarget('reply-all'),@@ -614,6 +645,8 @@ export function createThreadNavigation(navigateToNextMessage,activate,cancel,+ expandFocusedMessage,+ expandAllMessages,}));diff --git a/apps/web/src/features/email-view/components/EmailDetailView.tsx b/apps/web/src/features/email-view/components/EmailDetailView.tsxindex b42fbbc56b..a0623d1faa 100644--- a/apps/web/src/features/email-view/components/EmailDetailView.tsx+++ b/apps/web/src/features/email-view/components/EmailDetailView.tsx@@ -180,6 +180,8 @@ export function EmailDetailView(props: {onEmailReminderSaved: async () => {await listNavigation.afterReminderSaved?.();},+ extraFavoriteHotkey: { hotkey: 's', hotkeyToken: TOKENS.email.star },+ extraMuteHotkey: { hotkey: 'shift+m', hotkeyToken: TOKENS.email.mute },});let container: HTMLDivElement | undefined;diff --git a/apps/web/src/features/email-view/components/EmailHeader.tsx b/apps/web/src/features/email-view/components/EmailHeader.tsxindex 0e22cb65b1..975e9bebcc 100644--- a/apps/web/src/features/email-view/components/EmailHeader.tsx+++ b/apps/web/src/features/email-view/components/EmailHeader.tsx@@ -7,6 +7,7 @@ import {import { SidebarCreateButton } from '@app/components/view-shell/SidebarCreateButton';import { useSplitLayout } from '@components/app/split-layout/layout';import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';+import { registerHotkey } from '@core/hotkey/hotkeys';import { tourTarget } from '@ui/components/Tour';import { createSignal, Show } from 'solid-js';import { composeEmail } from '../compose-email';@@ -82,18 +83,31 @@ export function EmailHeader(props: EmailHeaderProps) {const selectedTabLabel = () =>EMAIL_TABS.find((tab) => tab.id === state.tab)?.label ?? 'Email';+ const focusSearch = () => {+ searchInput?.focus();+ searchInput?.select();+ return true;+ };+ const canSearch = () =>+ state.tab !== 'scheduled' && state.tab !== 'reminders';++ // Mail clients search with `/`; elsewhere it opens the app's search view.+ registerHotkey({+ hotkey: '/',+ scopeId: panel.splitHotkeyScope,+ description: 'Search email',+ condition: () => panel.isPanelActive() && canSearch(),+ keyDownHandler: focusSearch,+ });+// The view's control hotkeys are registered once, here, for the split scope.useViewControlHotkeys({scopeId: panel.splitHotkeyScope,enabled: panel.isPanelActive,search: {description: 'Search email',- condition: () => state.tab !== 'scheduled' && state.tab !== 'reminders',- run: () => {- searchInput?.focus();- searchInput?.select();- return true;- },+ condition: canSearch,+ run: focusSearch,},filter: {description: 'Filter email',diff --git a/apps/web/src/features/email-view/components/EmailList.tsx b/apps/web/src/features/email-view/components/EmailList.tsxindex b1297192c1..d2f2963a9f 100644--- a/apps/web/src/features/email-view/components/EmailList.tsx+++ b/apps/web/src/features/email-view/components/EmailList.tsx@@ -20,6 +20,7 @@ import { PullToRefresh } from '@components/app/mobile/PullToRefresh';import { SwipableRowProvider } from '@components/app/mobile/SwipableRow';import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';import { createSplitAutofocus } from '@components/app/split-layout/utils/createSplitAutofocus';+import { TOKENS } from '@core/hotkey/tokens';import { isTouchDevice } from '@core/mobile/isTouchDevice';import { debounce } from '@core/util/debounce';import { fireAndForget } from '@core/util/fireAndForget';@@ -331,6 +332,8 @@ export function EmailList(props: EmailListProps) {viewContext: entityActionViewContext,splitHandle: panel.handle,condition: listHasKeyboard,+ extraFavoriteHotkey: { hotkey: 's', hotkeyToken: TOKENS.email.star },+ extraMuteHotkey: { hotkey: 'shift+m', hotkeyToken: TOKENS.email.mute },});useEmailListHotkeys({diff --git a/apps/web/src/features/email-view/components/EmailRowActions.tsx b/apps/web/src/features/email-view/components/EmailRowActions.tsxindex e326c3b9c7..1538b0f14b 100644--- a/apps/web/src/features/email-view/components/EmailRowActions.tsx+++ b/apps/web/src/features/email-view/components/EmailRowActions.tsx@@ -51,6 +51,7 @@ export function EmailStarAction(props: {label={props.starred ? 'Unstar email' : 'Star email'}class={props.starred ? 'text-ink-muted' : 'text-ink-extra-muted'}tooltip={props.starred ? 'Remove from favorites' : 'Add to favorites'}+ hotkey={TOKENS.email.star}aria-pressed={props.starred}disabled={props.pending}onClick={props.onStar}diff --git a/apps/web/src/features/email-view/email-view.tsx b/apps/web/src/features/email-view/email-view.tsxindex cd4810df11..b041e18f81 100644--- a/apps/web/src/features/email-view/email-view.tsx+++ b/apps/web/src/features/email-view/email-view.tsx@@ -38,6 +38,7 @@ import { EmailViewProvider, useEmailView } from './email-view-context';import type { EmailListPane } from './reader-pane';import { emailTour } from './tour';import type { EmailTab, EmailViewStateOptions } from './types';+import { useEmailViewHotkeys } from './use-email-view-hotkeys';import { useReadingPaneHotkey } from './use-reading-pane-hotkey';export type EmailViewProps = {@@ -213,7 +214,14 @@ function EmailMobileLayout(props: ParentProps) {function EmailViewRoot() {const panel = useSplitPanelOrThrow();- const { readingPane, setReadingPane } = useEmailView();+ const {+ state,+ setTab,+ selectedThread,+ list: listController,+ readingPane,+ setReadingPane,+ } = useEmailView();const [listElement, setListElement] = createSignal<HTMLDivElement>();const [listPane, setListPane] = createSignal<EmailListPane>();const focusList = () => listElement()?.focus();@@ -227,6 +235,20 @@ function EmailViewRoot() {setReadingPane,});+ useEmailViewHotkeys({+ scopeId: panel.splitHotkeyScope,+ enabled: () => panel.isPanelActive() && !isTouchDevice(),+ tab: () => state.tab,+ setTab,+ // Beside the reading pane the list stays on screen with a thread open;+ // without it an open thread replaces the list.+ listHasKeyboard: () => {+ const pane = listPane();+ return pane ? !pane.readerHasKeyboard() : selectedThread() === undefined;+ },+ hasSelection: () => listController.selection.count() > 0,+ });+const list = () => (<Suspense fallback={<EmailListFallback />}><EmailList ref={setListElement} pane={listPane()} />diff --git a/apps/web/src/features/email-view/use-email-list-hotkeys.ts b/apps/web/src/features/email-view/use-email-list-hotkeys.tsindex c5f625d154..caabc7661d 100644--- a/apps/web/src/features/email-view/use-email-list-hotkeys.ts+++ b/apps/web/src/features/email-view/use-email-list-hotkeys.ts@@ -60,6 +60,8 @@ export function useEmailListHotkeys(options: UseEmailListHotkeysOptions) {options.clearSelection();return true;},+ // Without a selection, Escape returns the view to Signal (email-view).+ registrationType: 'add',}).withGroup(group);onCleanup(() => group.dispose());diff --git a/apps/web/src/features/email-view/use-email-view-hotkeys.test.tsx b/apps/web/src/features/email-view/use-email-view-hotkeys.test.tsxnew file mode 100644index 0000000000..c792858766--- /dev/null+++ b/apps/web/src/features/email-view/use-email-view-hotkeys.test.tsx@@ -0,0 +1,168 @@+import { GO_TO_COMMAND_SCOPE } from '@app/constants/hotkeys';+import {+ attachGlobalDOMScope,+ registerHotkey,+ useHotKeyRoot,+ useHotkeyDOMScope,+} from '@core/hotkey/hotkeys';+import { setActiveScope } from '@core/hotkey/state';+import { isScopeInActiveBranch } from '@core/hotkey/utils';+import { MutationUndoProvider, useMutationUndoContext } from '@queries/undo';+import { render } from '@solidjs/testing-library';+import { createSignal } from 'solid-js';+import { afterEach, expect, it, vi } from 'vitest';+import type { EmailTab } from './constants';+import { useEmailViewHotkeys } from './use-email-view-hotkeys';++afterEach(() => setActiveScope('global'));++function press(key: string, init: KeyboardEventInit = {}) {+ document.dispatchEvent(+ new KeyboardEvent('keydown', { key, bubbles: true, ...init })+ );+ document.dispatchEvent(new KeyboardEvent('keyup', { key, bubbles: true }));+}++function setup(initialTab: EmailTab = 'noise') {+ const goHome = vi.fn(() => true);+ const openCreateMenu = vi.fn(() => true);+ const [tab, setTab] = createSignal<EmailTab>(initialTab);+ let pushUndo!: ReturnType<typeof useMutationUndoContext>['pushUndo'];++ function Harness() {+ useHotKeyRoot();+ const [attachEmail, emailScope] = useHotkeyDOMScope('email-split');+ // The reading pane: a child scope, as in EmailReader.+ const [attachReader, readerScope] = useHotkeyDOMScope('email-reader');+ pushUndo = useMutationUndoContext().pushUndo;+ // The app-wide go-to letter, registered by the sidebar.+ registerHotkey({+ hotkey: 'g',+ scopeId: 'global',+ description: 'Go to',+ keyDownHandler: () => true,+ activateCommandScopeId: GO_TO_COMMAND_SCOPE,+ registrationType: 'add',+ hide: true,+ });+ // The app-wide Create menu, registered by GlobalHotkeys.+ registerHotkey({+ hotkey: 'c',+ scopeId: 'global',+ description: 'Create',+ keyDownHandler: openCreateMenu,+ });+ const registerHome = () =>+ registerHotkey({+ hotkey: ['h', 'i'],+ scopeId: GO_TO_COMMAND_SCOPE,+ description: 'Go to Home',+ keyDownHandler: goHome,+ registrationType: 'add',+ });+ registerHome();+ useEmailViewHotkeys({+ scopeId: emailScope,+ enabled: () => true,+ tab,+ setTab,+ listHasKeyboard: () => !isScopeInActiveBranch(readerScope),+ hasSelection: () => false,+ });+ // Flags loading later re-register the sidebar's letters.+ registerHome();+ return (+ <div ref={(element) => attachGlobalDOMScope(element)}>+ <div ref={attachEmail} tabIndex={0} data-testid="email">+ <div ref={attachReader} tabIndex={0} data-testid="reader" />+ </div>+ <button type="button">Elsewhere</button>+ </div>+ );+ }++ const view = render(() => (+ <MutationUndoProvider>+ <Harness />+ </MutationUndoProvider>+ ));+ return { view, goHome, openCreateMenu, tab, pushUndo: () => pushUndo };+}++it('goes to email tabs with g sequences only while Email is focused', () => {+ const { view, goHome, tab } = setup();+ view.getByTestId('email').focus();++ press('g');+ press('i');+ expect(tab()).toBe('important');+ expect(goHome).not.toHaveBeenCalled();++ view.getByRole('button', { name: 'Elsewhere' }).focus();+ press('g');+ press('i');+ expect(goHome).toHaveBeenCalledOnce();+});++it('leaves g h to Home inside Email', () => {+ const { view, goHome, tab } = setup();+ view.getByTestId('email').focus();++ press('g');+ press('h');+ expect(goHome).toHaveBeenCalledOnce();+ expect(tab()).toBe('noise');+});++it('returns to Signal on Escape and leaves c to the Create menu', () => {+ const { view, openCreateMenu, tab } = setup('archived');+ view.getByTestId('email').focus();++ press('Escape');+ expect(tab()).toBe('important');+ press('c');+ expect(openCreateMenu).toHaveBeenCalledOnce();+});++it('undoes the latest action with z', () => {+ const { view, pushUndo } = setup();+ const undo = vi.fn();+ pushUndo()({ undo });+ view.getByTestId('email').focus();++ press('z');+ expect(undo).toHaveBeenCalledOnce();+});++it('undoes once while z is held', () => {+ const { view, pushUndo } = setup();+ const first = vi.fn();+ const second = vi.fn();+ pushUndo()({ undo: first });+ pushUndo()({ undo: second });+ view.getByTestId('email').focus();++ document.dispatchEvent(+ new KeyboardEvent('keydown', { key: 'z', bubbles: true })+ );+ press('z', { repeat: true });+ expect(second).toHaveBeenCalledOnce();+ expect(first).not.toHaveBeenCalled();+});++it('works from the reading pane, where Escape stays with the reader', () => {+ const { view, openCreateMenu, tab, pushUndo } = setup('archived');+ const undo = vi.fn();+ pushUndo()({ undo });+ view.getByTestId('reader').focus();++ press('Escape');+ expect(tab()).toBe('archived');+ press('c');+ expect(openCreateMenu).toHaveBeenCalledOnce();+ press('z');+ expect(undo).toHaveBeenCalledOnce();+ press('g');+ press('t');+ expect(tab()).toBe('sent');+});diff --git a/apps/web/src/features/email-view/use-email-view-hotkeys.ts b/apps/web/src/features/email-view/use-email-view-hotkeys.tsnew file mode 100644index 0000000000..4dfe03f804--- /dev/null+++ b/apps/web/src/features/email-view/use-email-view-hotkeys.ts@@ -0,0 +1,97 @@+import { GO_TO_COMMAND_SCOPE } from '@app/constants/hotkeys';+import { toast } from '@core/component/Toast/Toast';+import { createHotkeyGroup, registerHotkey } from '@core/hotkey/hotkeys';+import { HOTKEY_PRIORITY_HIGH, type ValidHotkey } from '@core/hotkey/types';+import { isScopeInActiveBranch } from '@core/hotkey/utils';+import { fireAndForget } from '@core/util/fireAndForget';+import { useMutationUndoContext } from '@queries/undo';+import { onCleanup } from 'solid-js';+import { DEFAULT_EMAIL_TAB, EMAIL_TABS, type EmailTab } from './constants';++/**+ * Mail-client "go to" keys (g then i for Signal, as in other mail clients).+ * While Email is focused they take the letters' app-wide meanings; elsewhere+ * the letters keep them (g t is still Tasks). Reminders has no letter so+ * `g h` still reaches Home.+ */+const EMAIL_GO_TO_TABS = [+ ['i', 'important'],+ ['o', 'noise'],+ ['s', 'favorites'],+ ['t', 'sent'],+ ['d', 'drafts'],+ ['e', 'archived'],+ ['a', 'all'],+] as const satisfies readonly (readonly [ValidHotkey, EmailTab])[];++export type UseEmailViewHotkeysOptions = {+ scopeId: string;+ enabled: () => boolean;+ tab: () => EmailTab;+ setTab: (tab: EmailTab) => void;+ /** The list is on screen and has the keyboard, not the reader or a thread. */+ listHasKeyboard: () => boolean;+ hasSelection: () => boolean;+};++/** Keys that work in Email's list, its reading pane and an open thread. */+export function useEmailViewHotkeys(options: UseEmailViewHotkeysOptions) {+ const undo = useMutationUndoContext();+ const group = createHotkeyGroup();++ for (const [key, tab] of EMAIL_GO_TO_TABS) {+ const label = EMAIL_TABS.find((item) => item.id === tab)?.label ?? tab;+ registerHotkey({+ hotkey: key,+ scopeId: GO_TO_COMMAND_SCOPE,+ description: `Go to ${label}`,+ // `g` re-parents the go-to scope onto the scope it was pressed in.+ condition: () =>+ options.enabled() && isScopeInActiveBranch(options.scopeId),+ keyDownHandler: () => {+ options.setTab(tab);+ return true;+ },+ // Coexist with, and run before, the app-wide letters.+ registrationType: 'add',+ handlerPriority: HOTKEY_PRIORITY_HIGH,+ sheetSection: 'view',+ }).withGroup(group);+ }++ registerHotkey({+ hotkey: 'escape',+ scopeId: options.scopeId,+ description: `Back to ${+ EMAIL_TABS.find((item) => item.id === DEFAULT_EMAIL_TAB)?.label+ }`,+ condition: () =>+ options.enabled() &&+ options.listHasKeyboard() &&+ !options.hasSelection() &&+ options.tab() !== DEFAULT_EMAIL_TAB,+ keyDownHandler: () => {+ options.setTab(DEFAULT_EMAIL_TAB);+ return true;+ },+ registrationType: 'add',+ }).withGroup(group);++ registerHotkey({+ hotkey: 'z',+ scopeId: options.scopeId,+ description: 'Undo',+ condition: () => options.enabled() && undo.canUndo(),+ keyDownHandler: (e) => {+ // A held key would undo one action per repeat.+ if (e?.repeat) return true;+ fireAndForget(+ undo.undo({ onError: () => toast.failure('Failed to undo') }),+ 'email-view-hotkeys'+ );+ return true;+ },+ }).withGroup(group);++ onCleanup(() => group.dispose());+}diff --git a/apps/web/src/features/next-soup/actions/use-block-entity-commands.ts b/apps/web/src/features/next-soup/actions/use-block-entity-commands.tsindex 9a898eca20..a4f3e842c5 100644--- a/apps/web/src/features/next-soup/actions/use-block-entity-commands.ts+++ b/apps/web/src/features/next-soup/actions/use-block-entity-commands.ts@@ -12,7 +12,8 @@ import { useQuickAccess } from '@core/context/quickAccess';import { useUserId } from '@core/context/user';import { HotkeyTags } from '@core/hotkey/constants';import { createHotkeyGroup, registerHotkey } from '@core/hotkey/hotkeys';-import { TOKENS } from '@core/hotkey/tokens';+import { type HotkeyToken, TOKENS } from '@core/hotkey/tokens';+import type { ValidHotkey } from '@core/hotkey/types';import { blockHotkeyScopeSignal } from '@core/signal/blockElement';import { fireAndForget } from '@core/util/fireAndForget';import { type EntityData, isEmailEntity, isTaskEntity } from '@entity';@@ -59,6 +60,10 @@ export type UseBlockEntityCommandsOptions = {resolveEntity?: () => EntityData | undefined;onDeleted?: () => void;onEmailReminderSaved?: () => void | Promise<void>;+ /** A second key for Favorite, such as Email's `s` star. */+ extraFavoriteHotkey?: { hotkey: ValidHotkey; hotkeyToken: HotkeyToken };+ /** A key for Mute, such as Email's `shift+m`. */+ extraMuteHotkey?: { hotkey: ValidHotkey; hotkeyToken: HotkeyToken };};export const useBlockEntityCommands = (@@ -324,10 +329,7 @@ export const useBlockEntityCommands = (tags: [HotkeyTags.SelectionModification],}).withGroup(group);- // Favorite - 'opt+f' (macOS emits 'ƒ'; normalizeEventKeyPress maps it back to 'f')- registerHotkey({- hotkey: ['opt+f'],- hotkeyToken: TOKENS.entity.action.favorite,+ const favoriteCommand = {scopeId,description: () => {const entity = getEntity();@@ -346,9 +348,23 @@ export const useBlockEntityCommands = (const entity = getEntity();return entity !== undefined && favoriteAction.canExecute(entity);},- displayPriority: 10,+ displayPriority: 10 as const,tags: [HotkeyTags.SelectionModification],+ };+ // Favorite - 'opt+f' (macOS emits 'ƒ'; normalizeEventKeyPress maps it back to 'f')+ registerHotkey({+ hotkey: 'opt+f',+ hotkeyToken: TOKENS.entity.action.favorite,+ ...favoriteCommand,}).withGroup(group);+ if (options.extraFavoriteHotkey) {+ // Hidden so the command menu lists Favorite once.+ registerHotkey({+ ...options.extraFavoriteHotkey,+ ...favoriteCommand,+ hide: true,+ }).withGroup(group);+ }// Mute notifications (command menu only, no keybinding)registerHotkey({@@ -369,8 +385,7 @@ export const useBlockEntityCommands = (tags: [HotkeyTags.SelectionModification],}).withGroup(group);- registerHotkey({- hotkeyToken: TOKENS.entity.action.mute,+ const muteCommand = {scopeId,description: () => {const entity = getEntity();@@ -389,9 +404,21 @@ export const useBlockEntityCommands = (const entity = getEntity();return entity !== undefined && muteAction.canExecute(entity);},- displayPriority: 10,+ displayPriority: 10 as const,tags: [HotkeyTags.SelectionModification],+ };+ registerHotkey({+ hotkeyToken: TOKENS.entity.action.mute,+ ...muteCommand,}).withGroup(group);+ if (options.extraMuteHotkey) {+ // Hidden so the command menu lists Mute once.+ registerHotkey({+ ...options.extraMuteHotkey,+ ...muteCommand,+ hide: true,+ }).withGroup(group);+ }registerHotkey({scopeId,diff --git a/apps/web/src/features/next-soup/actions/use-entity-action-hotkeys.ts b/apps/web/src/features/next-soup/actions/use-entity-action-hotkeys.tsindex 1bbdf6cde9..6e5c50c185 100644--- a/apps/web/src/features/next-soup/actions/use-entity-action-hotkeys.ts+++ b/apps/web/src/features/next-soup/actions/use-entity-action-hotkeys.ts@@ -7,7 +7,8 @@ import type { SplitHandle } from '@components/app/split-layout/layoutManager';import { useUserId } from '@core/context/user';import { HotkeyTags } from '@core/hotkey/constants';import { createHotkeyGroup, registerHotkey } from '@core/hotkey/hotkeys';-import { TOKENS } from '@core/hotkey/tokens';+import { type HotkeyToken, TOKENS } from '@core/hotkey/tokens';+import type { ValidHotkey } from '@core/hotkey/types';import { fireAndForget } from '@core/util/fireAndForget';import { type EntityData, isEmailEntity, isTaskEntity } from '@entity';import { Telemetry } from '@macro-inc/observability';@@ -59,6 +60,10 @@ type UseEntityActionHotkeysOptions = {enableDeleteHotkey?: boolean;/** A list that completes its own rows, such as Home's work feed. */markDoneDelegate?: () => MarkDoneDelegate | undefined;+ /** A second key for Favorite, such as Email's `s` star. */+ extraFavoriteHotkey?: { hotkey: ValidHotkey; hotkeyToken: HotkeyToken };+ /** A key for Mute, such as Email's `shift+m`. */+ extraMuteHotkey?: { hotkey: ValidHotkey; hotkeyToken: HotkeyToken };};export const useEntityActionHotkeys = (@@ -381,10 +386,7 @@ export const useEntityActionHotkeys = (tags: [HotkeyTags.SelectionModification],}).withGroup(group);- // Favorite - 'opt+f' (macOS emits 'ƒ'; normalizeEventKeyPress maps it back to 'f')- registerHotkey({- hotkey: ['opt+f'],- hotkeyToken: TOKENS.entity.action.favorite,+ const favoriteCommand = {scopeId,description: () => {const entities = getEntitiesForAction();@@ -409,9 +411,23 @@ export const useEntityActionHotkeys = (const entities = getEntitiesForAction();return entities.length > 0 && entities.every(favoriteAction.canExecute);},- displayPriority: 10,+ displayPriority: 10 as const,tags: [HotkeyTags.SelectionModification],+ };+ // Favorite - 'opt+f' (macOS emits 'ƒ'; normalizeEventKeyPress maps it back to 'f')+ registerHotkey({+ hotkey: 'opt+f',+ hotkeyToken: TOKENS.entity.action.favorite,+ ...favoriteCommand,}).withGroup(group);+ if (options.extraFavoriteHotkey) {+ // Hidden so the command menu lists Favorite once.+ registerHotkey({+ ...options.extraFavoriteHotkey,+ ...favoriteCommand,+ hide: true,+ }).withGroup(group);+ }// Mute notifications (command menu only, no keybinding)registerHotkey({@@ -434,8 +450,7 @@ export const useEntityActionHotkeys = (tags: [HotkeyTags.SelectionModification],}).withGroup(group);- registerHotkey({- hotkeyToken: TOKENS.entity.action.mute,+ const muteCommand = {scopeId,description: () => {const entities = getEntitiesForAction();@@ -460,9 +475,21 @@ export const useEntityActionHotkeys = (const entities = getEntitiesForAction();return entities.length > 0 && entities.every(muteAction.canExecute);},- displayPriority: 10,+ displayPriority: 10 as const,tags: [HotkeyTags.SelectionModification],+ };+ registerHotkey({+ hotkeyToken: TOKENS.entity.action.mute,+ ...muteCommand,}).withGroup(group);+ if (options.extraMuteHotkey) {+ // Hidden so the command menu lists Mute once.+ registerHotkey({+ ...options.extraMuteHotkey,+ ...muteCommand,+ hide: true,+ }).withGroup(group);+ }// Copy - 'cmd+d'registerHotkey({diff --git a/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.ts b/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.tsindex 546f86ccae..d91ca8d689 100644--- a/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.ts+++ b/apps/web/src/features/next-soup/soup-view/use-soup-view-hotkeys.ts@@ -84,9 +84,9 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {const group = createHotkeyGroup();- // home - Jump to top of list+ // home, cmd+arrowup - Jump to top of listregisterHotkey({- hotkey: ['home'],+ hotkey: ['home', 'cmd+arrowup'],scopeId,hotkeyToken: TOKENS.entity.jump.home,description: 'Go to top of list',@@ -117,9 +117,9 @@ export const useSoupViewHotkeys = (options: UseSoupViewHotkeysOptions) => {registrationType: 'add',}).withGroup(group);- // shift+g, end - Jump to bottom of list+ // shift+g, end, cmd+arrowdown - Jump to bottom of listregisterHotkey({- hotkey: ['shift+g', 'end'],+ hotkey: ['shift+g', 'end', 'cmd+arrowdown'],scopeId,hotkeyToken: TOKENS.entity.jump.end,description: 'Go to bottom of list',diff --git a/apps/web/src/features/settings/Shortcuts.tsx b/apps/web/src/features/settings/Shortcuts.tsxindex bc9497baa6..6667ff91af 100644--- a/apps/web/src/features/settings/Shortcuts.tsx+++ b/apps/web/src/features/settings/Shortcuts.tsx@@ -1007,6 +1007,55 @@ const shortcutSections: ShortcutSection[] = [{title: 'Email',items: [+ { keys: ['/'], codes: ['Slash'], description: 'Search email' },+ { keys: ['s'], codes: ['KeyS'], description: 'Star or unstar' },+ {+ keys: ['shift+m'],+ codes: ['ShiftLeft', 'KeyM'],+ description: 'Mute or unmute',+ },+ { keys: ['z'], codes: ['KeyZ'], description: 'Undo the last action' },+ {+ keys: ['escape'],+ codes: ['Escape'],+ description: 'Back to the list, then to Signal',+ },+ {+ keys: ['g'],+ codes: ['KeyG'],+ description:+ 'Then i Signal, o Noise, s Favorites, t Sent, d Drafts, e Archived, a All',+ },+ {+ keys: ['n', 'arrowdown'],+ codes: ['KeyN'],+ description: 'Next message',+ },+ {+ keys: ['p', 'arrowup'],+ codes: ['KeyP'],+ description: 'Previous message',+ },+ {+ keys: ['o'],+ codes: ['KeyO'],+ description: 'Expand or collapse message',+ },+ {+ keys: ['shift+o'],+ codes: ['ShiftLeft', 'KeyO'],+ description: 'Expand all messages',+ },+ {+ keys: [`${cmdOrCtrl}+arrowup`],+ codes: [CmdOrCtrl, 'ArrowUp'],+ description: 'Jump to top of list',+ },+ {+ keys: [`${cmdOrCtrl}+arrowdown`],+ codes: [CmdOrCtrl, 'ArrowDown'],+ description: 'Jump to bottom of list',+ },{keys: ['shift+v'],codes: ['ShiftLeft', 'KeyV'],@@ -1014,6 +1063,41 @@ const shortcutSections: ShortcutSection[] = [},],},+ {+ title: 'Email drafts',+ items: [+ {+ keys: [`shift+${cmdOrCtrl}+.`, `shift+${cmdOrCtrl}+d`],+ codes: ['ShiftLeft', CmdOrCtrl, 'Period'],+ description: 'Discard draft',+ },+ {+ keys: [`shift+${cmdOrCtrl}+u`],+ codes: ['ShiftLeft', CmdOrCtrl, 'KeyU'],+ description: 'Attach files',+ },+ {+ keys: [`shift+${cmdOrCtrl}+x`],+ codes: ['ShiftLeft', CmdOrCtrl, 'KeyX'],+ description: 'Strikethrough',+ },+ {+ keys: [`shift+${cmdOrCtrl}+7`],+ codes: ['ShiftLeft', CmdOrCtrl, 'Digit7'],+ description: 'Numbered list',+ },+ {+ keys: [`shift+${cmdOrCtrl}+8`],+ codes: ['ShiftLeft', CmdOrCtrl, 'Digit8'],+ description: 'Bulleted list',+ },+ {+ keys: [`shift+${cmdOrCtrl}+9`],+ codes: ['ShiftLeft', CmdOrCtrl, 'Digit9'],+ description: 'Quote',+ },+ ],+ },];const [hoveredCodes, setHoveredCodes] = createSignal<string[]>([]);diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/keyboard-shortcuts/keyboardShortcutsPlugin.test.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/keyboard-shortcuts/keyboardShortcutsPlugin.test.tsindex bc6918b87f..fa8096ef04 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/keyboard-shortcuts/keyboardShortcutsPlugin.test.ts+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/keyboard-shortcuts/keyboardShortcutsPlugin.test.ts@@ -4,14 +4,23 @@ import {$getRoot,$getSelection,$isRangeSelection,+ COMMAND_PRIORITY_HIGH,createEditor,KEY_ARROW_RIGHT_COMMAND,+ KEY_DOWN_COMMAND,type LexicalEditor,ParagraphNode,TextNode,} from 'lexical';import { describe, expect, test } from 'vitest';-import { keyboardShortcutsPlugin } from './keyboardShortcutsPlugin';+import {+ NODE_TRANSFORM,+ type NodeTransformType,+} from '../node-transform/nodeTransformPlugin';+import {+ keyboardShortcutsPlugin,+ ListAndQuoteShortcuts,+} from './keyboardShortcutsPlugin';function createTestEditor(): LexicalEditor {const editor = createEditor({@@ -203,3 +212,36 @@ describe('keyboardShortcutsPlugin', () => {});});});++describe('ListAndQuoteShortcuts', () => {+ test.each([+ ['Digit7', 'list-number'],+ ['Digit8', 'list-bullet'],+ ['Digit9', 'quote'],+ ] as const)('mod+shift+%s formats the block as %s', (code, transform) => {+ const editor = createTestEditor();+ keyboardShortcutsPlugin({ shortcuts: ListAndQuoteShortcuts })(editor);+ const dispatched: NodeTransformType[] = [];+ editor.registerCommand(+ NODE_TRANSFORM,+ (payload) => {+ dispatched.push(payload);+ return true;+ },+ COMMAND_PRIORITY_HIGH+ );++ const press = (init: KeyboardEventInit) =>+ editor.dispatchCommand(+ KEY_DOWN_COMMAND,+ new KeyboardEvent('keydown', { code, ...init })+ );++ // Without the shift modifier the digit is left to the editor.+ press({ metaKey: true, ctrlKey: true });+ expect(dispatched).toEqual([]);++ press({ shiftKey: true, metaKey: true, ctrlKey: true });+ expect(dispatched).toEqual([transform]);+ });+});diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/keyboard-shortcuts/keyboardShortcutsPlugin.ts b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/keyboard-shortcuts/keyboardShortcutsPlugin.tsindex a22971f669..e87e38c7f5 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/plugins/keyboard-shortcuts/keyboardShortcutsPlugin.ts+++ b/apps/web/src/lib/core/component/LexicalMarkdown/plugins/keyboard-shortcuts/keyboardShortcutsPlugin.ts@@ -16,6 +16,10 @@ import {type RangeSelection,type TextFormatType,} from 'lexical';+import {+ NODE_TRANSFORM,+ type NodeTransformType,+} from '../node-transform/nodeTransformPlugin';const META_OR_CTRL = IS_MAC ? 'meta' : 'ctrl';@@ -206,3 +210,25 @@ export const DefaultShortcuts: Shortcut[] = [priority: 0,},];++const blockShortcut = (+ digit: string,+ transform: NodeTransformType+): Shortcut => ({+ label: `${META_OR_CTRL}+shift+${digit}`,+ test: (e) =>+ e.code === `Digit${digit}` &&+ e.shiftKey &&+ metaOrCtrl(e.metaKey, e.ctrlKey),+ handler: (editor) => {+ editor.dispatchCommand(NODE_TRANSFORM, transform);+ },+ priority: 0,+});++/** The mail-client block formats: numbered list, bulleted list, and quote. */+export const ListAndQuoteShortcuts: Shortcut[] = [+ blockShortcut('7', 'list-number'),+ blockShortcut('8', 'list-bullet'),+ blockShortcut('9', 'quote'),+];diff --git a/apps/web/src/lib/core/hotkey/getCommands.ts b/apps/web/src/lib/core/hotkey/getCommands.tsindex 3065115ae8..19dc8b53c0 100644--- a/apps/web/src/lib/core/hotkey/getCommands.ts+++ b/apps/web/src/lib/core/hotkey/getCommands.ts@@ -91,6 +91,18 @@ export function getActiveCommandsFromScope(: commands;}+/** Every key a command registered in this scope would run for right now. */+export function getRunnableHotkeys(scopeId: string): Set<ValidHotkey> {+ return new Set(+ getActiveCommandsFromScope(scopeId, {+ limitToCurrentScope: true,+ hideCommandsWithoutHotkeys: true,+ ignoreInputFocused: true,+ includeHidden: true,+ }).flatMap((command) => command.hotkeys ?? [])+ );+}+const filterCommands = (displayOptions: sortAndFilterOptions) => {return (command: HotkeyCommand) => {const hideValue =diff --git a/apps/web/src/lib/core/hotkey/shortcut-sheet.test.ts b/apps/web/src/lib/core/hotkey/shortcut-sheet.test.tsindex c9e9447dcd..f13fc81e6d 100644--- a/apps/web/src/lib/core/hotkey/shortcut-sheet.test.ts+++ b/apps/web/src/lib/core/hotkey/shortcut-sheet.test.ts@@ -1,6 +1,6 @@import { createRoot, createSignal } from 'solid-js';import { afterEach, expect, test } from 'vitest';-import { getShortcutSheet } from './getCommands';+import { getRunnableHotkeys, getShortcutSheet } from './getCommands';import { registerHotkey } from './hotkeys';import { hotkeyScopeTree } from './state';import { registerScope, removeScope } from './utils';@@ -166,3 +166,39 @@ test('keeps the keys of a partly shadowed command and follows handler priority',bindings: [['x']],});});++test('runnable keys include hidden commands and only those whose condition holds', () => {+ const goTo = leaderScope('runnable-go-to');+ const [viewFocused, setViewFocused] = createSignal(false);+ createRoot((dispose) => {+ disposers.push(dispose);+ const handler = () => true;+ registerHotkey({+ scopeId: goTo,+ hotkey: 'h',+ description: 'Go to Home',+ keyDownHandler: handler,+ registrationType: 'add',+ });+ registerHotkey({+ scopeId: goTo,+ hotkey: 's',+ description: 'Go to Favorites',+ keyDownHandler: handler,+ condition: viewFocused,+ registrationType: 'add',+ });+ registerHotkey({+ scopeId: goTo,+ hotkey: 'g',+ description: 'Go to top',+ keyDownHandler: handler,+ hide: true,+ registrationType: 'add',+ });+ });++ expect([...getRunnableHotkeys(goTo)].sort()).toEqual(['g', 'h']);+ setViewFocused(true);+ expect([...getRunnableHotkeys(goTo)].sort()).toEqual(['g', 'h', 's']);+});diff --git a/apps/web/src/lib/core/hotkey/tokens.ts b/apps/web/src/lib/core/hotkey/tokens.tsindex 8fbe3425bc..1060882b00 100644--- a/apps/web/src/lib/core/hotkey/tokens.ts+++ b/apps/web/src/lib/core/hotkey/tokens.ts@@ -153,11 +153,17 @@ export const TOKENS = {previousMessage: 'email.previousMessage',nextMessage: 'email.nextMessage',cancelReply: 'email.cancelReply',+ discardDraft: 'email.discardDraft',+ attach: 'email.attach',+ expandMessage: 'email.expandMessage',+ expandAllMessages: 'email.expandAllMessages',trash: 'email.trash',blockSender: 'email.blockSender',markSenderSignal: 'email.markSenderSignal',markSenderNoise: 'email.markSenderNoise',toggleReadingPane: 'email.toggleReadingPane',+ star: 'email.star',+ mute: 'email.mute',compose: {edit: {recipients: 'email.compose.edit.recipients',diff --git a/apps/web/src/lib/core/util/filePicker.ts b/apps/web/src/lib/core/util/filePicker.tsnew file mode 100644index 0000000000..7e1cb358a7--- /dev/null+++ b/apps/web/src/lib/core/util/filePicker.ts@@ -0,0 +1,121 @@+/**+ * Imperative file and folder pickers. Kept apart from the upload module so a+ * caller that only needs the picker does not load the upload pipeline.+ */++import { fireAndForget } from '@core/util/fireAndForget';++type UploadPickerCleanup = () => void;++type UploadPickerOptions = {+ multiple?: boolean;+ acceptedMimeTypes?: string[];+ acceptedFileExtensions?: string[];+ directory?: boolean;+ filterDotfiles?: boolean;+};++function buildAcceptString(options?: UploadPickerOptions): string {+ const mimeTypes = options?.acceptedMimeTypes?.join(',');+ const fileExtensions = options?.acceptedFileExtensions?.join(',.');+ let acceptString = '';+ if (mimeTypes) {+ acceptString += `${mimeTypes},`;+ }+ if (fileExtensions) {+ acceptString += `.${fileExtensions}`;+ }+ return acceptString;+}++function filterFilesFromInput(+ fileList: FileList | null,+ options?: UploadPickerOptions+): File[] {+ const filterDotfiles = options?.filterDotfiles ?? true;+ const files = Array.from(fileList || []);+ return filterDotfiles ? files.filter((f) => !f.name.startsWith('.')) : files;+}++function createHiddenFileInput(+ options?: UploadPickerOptions+): HTMLInputElement {+ const input = document.createElement('input');+ input.type = 'file';+ input.style.display = 'none';+ input.multiple = options?.multiple ?? false;+ input.accept = buildAcceptString(options);++ // Enable folder picking in browsers that support it (Safari/Chrome/WebKit)+ if (options?.directory) {+ // property exists in TS lib for WebKit dir inputs on some setups+ (+ input as HTMLInputElement & { webkitdirectory?: boolean }+ ).webkitdirectory = true;+ // ensure attribute is present for environments that rely on it+ input.setAttribute('webkitdirectory', '');+ input.setAttribute('directory', '');+ }++ return input;+}++/**+ * Imperative picker for files/folders, using a hidden <input type="file" />.+ * Returns a cleanup function; you generally don't need it because the util+ * removes listeners and DOM nodes once a selection is made.+ */+function openUploadPicker(+ options: UploadPickerOptions,+ onSelect: (files: File[]) => void | Promise<void>+): UploadPickerCleanup {+ const input = createHiddenFileInput(options);++ const handleChange = () => {+ const files = filterFilesFromInput(input.files, options);+ // Always cleanup before invoking callback to avoid re-entrancy leaks+ cleanup();+ // Only call onSelect if there are files selected+ if (files.length > 0) {+ fireAndForget(onSelect(files), 'file-upload');+ }+ };++ const cleanup = () => {+ input.removeEventListener('change', handleChange);+ input.remove();+ };++ input.addEventListener('change', handleChange);+ document.body.appendChild(input);+ input.click();++ return cleanup;+}++export function openFilePicker(+ options: Omit<UploadPickerOptions, 'directory'> = {},+ onSelect: (files: File[]) => void | Promise<void>+): UploadPickerCleanup {+ return openUploadPicker(+ {+ ...options,+ directory: false,+ },+ onSelect+ );+}++export function openFolderPicker(+ options: Omit<UploadPickerOptions, 'directory'> = {},+ onSelect: (files: File[]) => void | Promise<void>+): UploadPickerCleanup {+ return openUploadPicker(+ {+ ...options,+ directory: true,+ multiple: options.multiple ?? true,+ },+ onSelect+ );+}diff --git a/apps/web/src/lib/core/util/upload.ts b/apps/web/src/lib/core/util/upload.tsindex 9222dea3e6..406fbdc83e 100644--- a/apps/web/src/lib/core/util/upload.ts+++ b/apps/web/src/lib/core/util/upload.ts@@ -21,6 +21,7 @@ import {blockAcceptsFileExtension,} from '@core/constant/allBlocks';import { heicConversionService } from '@core/heic/service';+import { openFilePicker, openFolderPicker } from '@core/util/filePicker';import { fireAndForget } from '@core/util/fireAndForget';import { holdAutomaticReload } from '@core/util/reloadForNewerBuild';import {@@ -40,125 +41,12 @@ import {upload as dssUpload,} from '@service-storage/util/upload';+export { openFilePicker, openFolderPicker };+const MAX_FILE_BYTE_SIZE = 2 * 1000 * 1000 * 1000; // 2GBtype UploadDestination = 'dss' | 'static';-type UploadPickerCleanup = () => void;--type UploadPickerOptions = {- multiple?: boolean;- acceptedMimeTypes?: string[];- acceptedFileExtensions?: string[];- directory?: boolean;- filterDotfiles?: boolean;-};--function buildAcceptString(options?: UploadPickerOptions): string {- const mimeTypes = options?.acceptedMimeTypes?.join(',');- const fileExtensions = options?.acceptedFileExtensions?.join(',.');- let acceptString = '';- if (mimeTypes) {- acceptString += `${mimeTypes},`;- }- if (fileExtensions) {- acceptString += `.${fileExtensions}`;- }- return acceptString;-}--function filterFilesFromInput(- fileList: FileList | null,- options?: UploadPickerOptions-): File[] {- const filterDotfiles = options?.filterDotfiles ?? true;- const files = Array.from(fileList || []);- return filterDotfiles ? files.filter((f) => !f.name.startsWith('.')) : files;-}--function createHiddenFileInput(- options?: UploadPickerOptions-): HTMLInputElement {- const input = document.createElement('input');- input.type = 'file';- input.style.display = 'none';- input.multiple = options?.multiple ?? false;- input.accept = buildAcceptString(options);-- // Enable folder picking in browsers that support it (Safari/Chrome/WebKit)- if (options?.directory) {- // property exists in TS lib for WebKit dir inputs on some setups- (- input as HTMLInputElement & { webkitdirectory?: boolean }- ).webkitdirectory = true;- // ensure attribute is present for environments that rely on it- input.setAttribute('webkitdirectory', '');- input.setAttribute('directory', '');- }-- return input;-}--/**- * Imperative picker for files/folders, using a hidden <input type="file" />.- * Returns a cleanup function; you generally don't need it because the util- * removes listeners and DOM nodes once a selection is made.- */-function openUploadPicker(- options: UploadPickerOptions,- onSelect: (files: File[]) => void | Promise<void>-): UploadPickerCleanup {- const input = createHiddenFileInput(options);-- const handleChange = () => {- const files = filterFilesFromInput(input.files, options);- // Always cleanup before invoking callback to avoid re-entrancy leaks- cleanup();- // Only call onSelect if there are files selected- if (files.length > 0) {- fireAndForget(onSelect(files), 'file-upload');- }- };-- const cleanup = () => {- input.removeEventListener('change', handleChange);- input.remove();- };-- input.addEventListener('change', handleChange);- document.body.appendChild(input);- input.click();-- return cleanup;-}--export function openFilePicker(- options: Omit<UploadPickerOptions, 'directory'> = {},- onSelect: (files: File[]) => void | Promise<void>-): UploadPickerCleanup {- return openUploadPicker(- {- ...options,- directory: false,- },- onSelect- );-}--export function openFolderPicker(- options: Omit<UploadPickerOptions, 'directory'> = {},- onSelect: (files: File[]) => void | Promise<void>-): UploadPickerCleanup {- return openUploadPicker(- {- ...options,- directory: true,- multiple: options.multiple ?? true,- },- onSelect- );-}-type StaticUploadSuccessResult = {name: string;id: string;diff --git a/docs/agent-guide/email.md b/docs/agent-guide/email.mdindex 4a0d7d7b8d..8f3eb21b5c 100644--- a/docs/agent-guide/email.md+++ b/docs/agent-guide/email.md@@ -29,9 +29,27 @@ Unlike Calls, it lists only personal tags; team-shared tags are hidden,and its `New tag` action creates a personal tag with no Team sharing option.Full email client. Tabs: `Signal` / `Noise` / `Favorites` / `Sent` / `Scheduled` / `Calendar` / `Drafts` / `Shared` /-`Archived` / `All`. Compose via the `Email` button (or `Create` → `Email E`). On a fresh local user it+`Archived` / `All`, plus `Reminders` when reminders are enabled. Compose via the `Email` button (or `Create` → `Email E`). On a fresh local user itshows `Connect your email`; Gmail/Google Workspace and enabled Outlook connections-use provider consent. Most functionality needs a connected account. Search is `Ctrl+F` within the surface.+use provider consent. Most functionality needs a connected account. Search is `Ctrl+F` or `/` within the surface.++Mail-client keys work in the list, the reading pane, and the open thread while+Email is focused: `s` star, `z` undo the last action, and `g` then a letter+for a tab (`i` Signal, `o` Noise, `s` Favorites, `t` Sent, `d` Drafts, `e`+Archived, `a` All). These letters replace the app-wide `g` targets only inside+Email (`g t` is still Tasks elsewhere); `g h` still goes Home. `Escape` in a+list with nothing selected returns to Signal; in the reading pane it first+hands the keyboard back to the list. `?` lists every shortcut for the focused+view. `Shift+M` mutes the selected rows or the open thread, and `S` and+`Shift+M` also work on a thread opened in its own split. In a thread, `O` opens+or closes the selected message (the latest when none is selected), `Shift+O`+opens every message including the collapsed middle run, and `N`/`P` step+messages like the arrows. `Cmd+Up`/`Cmd+Down` jump to either end of a list.+In every composer `Cmd+Shift+.`, `Cmd+Shift+,` and `Cmd+Shift+D` discard the+draft exactly like its trash button, `Cmd+Shift+U` opens the attach picker, and+`Cmd+Shift+X`, `7`, `8` and `9` apply strikethrough, numbered list, bulleted+list and quote. Check discard from both a reply (the reply closes) and+standalone compose (the view goes back), with focus in the body.Outlook connections support personal Outlook.com and individual Microsoft 365inboxes. Choose the inbox explicitly when testing mixed-provider accounts. Thediff --git a/docs/agent-guide/navigation.md b/docs/agent-guide/navigation.mdindex 590f925fac..41fb18cb3f 100644--- a/docs/agent-guide/navigation.md+++ b/docs/agent-guide/navigation.md@@ -950,11 +950,14 @@ restart rules still apply.would describe the menu. A view's `g` letters are listed under that view.- `c` then `d`/`t`/`e`/`m`/`a` — create doc / task / email / channel / AI chat.Single-letter shortcuts only work when no editor has focus; press `Escape` first.-- `/` — search everything. `j`/`k` — move in lists. `e` — mark done.+- `/` — search everything (in Email it focuses email search). `j`/`k` — move in+ lists. `e` — mark done.- `#` — move email to Trash, with an Undo toast. Works on the selected or focusedrows in a mail list and on the thread open in an email detail or block. Emailonly; other entity types keep Delete/Backspace and do not answer `#`.-- `g` then `h` — Home; `g` then `i` remains an alias.+- `g` then `h` — Home; `g` then `i` remains an alias. While Email is focused,+ `g i`/`o`/`s`/`t`/`d`/`e`/`a` open its tabs instead (`g i` Signal, `g t` Sent;+ see `email.md`); `g h` still goes Home.- In Email and Tasks search, `Escape` returns focus to the list and keeps the query.Use the search field's clear button to clear it.- Splits: `` ` `` split, `Shift+H`/`Shift+L` move focus, `Shift+Esc` maximize.