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.

feat(email): bind '#' to move an email to Trash (#7201)

Peter Chinman96413bd8f14e
diff --git a/apps/web/src/features/next-soup/actions/make-delete-action.test.ts b/apps/web/src/features/next-soup/actions/make-delete-action.test.ts
index 02ac3a926f..8c27690c00 100644
--- a/apps/web/src/features/next-soup/actions/make-delete-action.test.ts
+++ b/apps/web/src/features/next-soup/actions/make-delete-action.test.ts
@@ -136,6 +136,59 @@ describe('makeDeleteAction.execute', () => {
expect.objectContaining({ entities: [doc] })
);
});
+
+ // The confirmation modal deletes through the DSS mutation, which cannot
+ // touch email at all, so an email that reached it was simply never deleted.
+ describe('email', () => {
+ const email = entity('email', { id: 'thread-1', linkId: 'link-1' });
+
+ beforeEach(() => {
+ mocks.trashEmails.mockReturnValue({
+ done: Promise.resolve(),
+ undo: vi.fn(),
+ });
+ });
+
+ it('trashes without a confirmation step', async () => {
+ const onDeleted = vi.fn();
+ const action = makeDeleteAction({ userId: () => ME, onDeleted });
+
+ await action.execute([email]);
+
+ expect(mocks.trashEmails).toHaveBeenCalledWith([
+ { id: 'thread-1', linkId: 'link-1' },
+ ]);
+ expect(mocks.openBulkEditModal).not.toHaveBeenCalled();
+ expect(mocks.success).toHaveBeenCalledWith(
+ 'Moved to Trash',
+ expect.anything()
+ );
+ expect(onDeleted).toHaveBeenCalledWith([email]);
+ });
+
+ it('drops trashed threads from split history', async () => {
+ mocks.splitManager = {};
+
+ await execute([email]);
+
+ const predicate = mocks.removeHistory.mock.calls[0][1] as (entry: {
+ id: string;
+ }) => boolean;
+ expect(predicate({ id: email.id })).toBe(true);
+ expect(predicate({ id: 'other' })).toBe(false);
+ });
+
+ it('still confirms the rest of a mixed selection', async () => {
+ const doc = entity('document', { id: 'doc-1' });
+
+ await execute([email, doc]);
+
+ expect(mocks.trashEmails).toHaveBeenCalledOnce();
+ expect(mocks.openBulkEditModal).toHaveBeenCalledWith(
+ expect.objectContaining({ entities: [doc] })
+ );
+ });
+ });
});
type DeleteModal = {
diff --git a/apps/web/src/features/next-soup/actions/make-delete-action.ts b/apps/web/src/features/next-soup/actions/make-delete-action.ts
index 87b742329d..cdcd6fea2b 100644
--- a/apps/web/src/features/next-soup/actions/make-delete-action.ts
+++ b/apps/web/src/features/next-soup/actions/make-delete-action.ts
@@ -5,6 +5,7 @@ import { globalRemoveFromSplitHistory } from '@components/app/split-layout/layou
import { toast } from '@core/component/Toast/Toast';
import {
createBulkDeleteDssItemsMutation,
+ type EmailEntity,
type EntityData,
isEmailEntity,
} from '@entity';
@@ -13,6 +14,59 @@ import type { SoupRow } from '../create-soup-state';
import { restoreSoupFocus, trashEmails } from '../utils';
import type { EntityActionListState } from './entity-action-context';
+/**
+ * Move email threads to Trash and drop them from split history.
+ *
+ * Emails never reach the confirmation modal: `createBulkDeleteDssItemsMutation`
+ * cannot delete them at all, and the TRASH label is reversible, so the Undo
+ * toast is the safety net the modal gives everything else.
+ */
+function trashEmailThreads(emails: EmailEntity[]) {
+ const handle = trashEmails(
+ emails.map((email) => ({ id: email.id, linkId: email.linkId }))
+ );
+
+ const splitManager = globalSplitManager();
+ if (splitManager) {
+ const entityIdSet = new Set(emails.map(({ id }) => id));
+ globalRemoveFromSplitHistory(splitManager, (entry) =>
+ entityIdSet.has(entry.id)
+ );
+ }
+
+ return handle;
+}
+
+function reportTrashedEmails(
+ handle: ReturnType<typeof trashEmails>,
+ count: number
+) {
+ const toastId = toast.success(
+ count > 1 ? `Moved ${count} items to Trash` : 'Moved to Trash',
+ {
+ actions: [
+ {
+ label: 'Undo',
+ icon: ArrowCounterClockwise,
+ onClick: () => {
+ if (toastId != null) toast.dismiss(toastId);
+ handle.undo().then(
+ () => toast.success('Restored from Trash'),
+ () => toast.failure('Failed to restore from Trash')
+ );
+ },
+ },
+ ],
+ duration: 10_000,
+ }
+ );
+
+ // Surface background API failures
+ handle.done.catch(() => {
+ toast.failure('Failed to move to Trash');
+ });
+}
+
type MakeDeleteOptions = {
userId: () => string | undefined;
onDeleted?: (entities: EntityData[]) => void;
@@ -115,8 +169,17 @@ export const makeDeleteAction = (options: MakeDeleteOptions) => {
const execute = async (entities: EntityData[]) => {
const reminders = entities.filter((e) => e.type === 'reminder');
- const rest = entities.filter((e) => e.type !== 'reminder');
+ const emails = entities.filter(isEmailEntity);
+ const rest = entities.filter(
+ (e) => e.type !== 'reminder' && e.type !== 'email'
+ );
void deleteRemindersNow(reminders);
+
+ if (emails.length > 0) {
+ reportTrashedEmails(trashEmailThreads(emails), emails.length);
+ options.onDeleted?.(emails);
+ }
+
if (rest.length === 0) return;
const cleanup = createDeletionCleanup();
@@ -218,17 +281,7 @@ export const makeDeleteAction = (options: MakeDeleteOptions) => {
};
const trashEmailEntities = () => {
- const handle = trashEmails(
- emailEntities.map((e) => ({ id: e.id, linkId: e.linkId }))
- );
-
- const splitManager = globalSplitManager();
- if (splitManager) {
- const entityIdSet = new Set(emailEntities.map(({ id }) => id));
- globalRemoveFromSplitHistory(splitManager, (entry) =>
- entityIdSet.has(entry.id)
- );
- }
+ const handle = trashEmailThreads(emailEntities);
soup.selection.clear();
const next = nextSurvivingRow(emailEntities.map((entity) => entity.id));
@@ -236,32 +289,7 @@ export const makeDeleteAction = (options: MakeDeleteOptions) => {
soup.focus.set(next?.id);
}
- const toastId = toast.success(
- emailEntities.length > 1
- ? `Moved ${emailEntities.length} items to Trash`
- : 'Moved to Trash',
- {
- actions: [
- {
- label: 'Undo',
- icon: ArrowCounterClockwise,
- onClick: () => {
- if (toastId != null) toast.dismiss(toastId);
- handle.undo().then(
- () => toast.success('Restored from Trash'),
- () => toast.failure('Failed to restore from Trash')
- );
- },
- },
- ],
- duration: 10_000,
- }
- );
-
- // Surface background API failures
- handle.done.catch(() => {
- toast.failure('Failed to move to Trash');
- });
+ reportTrashedEmails(handle, emailEntities.length);
restoreSoupFocus(next?.id);
};
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.ts
index 930d6244d6..12719eaa63 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
@@ -14,7 +14,12 @@ import { HotkeyTags } from '@core/hotkey/constants';
import { createHotkeyGroup, registerHotkey } from '@core/hotkey/hotkeys';
import { TOKENS } from '@core/hotkey/tokens';
import { blockHotkeyScopeSignal } from '@core/signal/blockElement';
-import { type EntityData, isDocumentEntity, isTaskEntity } from '@entity';
+import {
+ type EntityData,
+ isDocumentEntity,
+ isEmailEntity,
+ isTaskEntity,
+} from '@entity';
import { SYSTEM_PROPERTY_IDS } from '@property/constants';
import type { Property, PropertyDefinitionDomain } from '@property/types';
import { createEffect, onCleanup } from 'solid-js';
@@ -201,6 +206,14 @@ export const useBlockEntityCommands = (
return true;
};
+ const runDelete = () => {
+ const entity = getEntity();
+ if (!entity) return false;
+ if (!deleteAction.canExecute(entity)) return false;
+ deleteAction.execute([entity]);
+ return true;
+ };
+
const runMarkDone = () => {
const entity = getEntity();
if (!entity) return false;
@@ -257,19 +270,41 @@ export const useBlockEntityCommands = (
tags: [HotkeyTags.SelectionModification],
}).withGroup(group);
+ // Delete without a keybinding: Backspace belongs to whatever editor the
+ // block hosts, so the command menu is the only way in.
registerHotkey({
scopeId,
description: 'Delete item',
- keyDownHandler: () => {
+ keyDownHandler: runDelete,
+ condition: () => {
const entity = getEntity();
- if (!entity) return false;
- if (!deleteAction.canExecute(entity)) return false;
- deleteAction.execute([entity]);
- return true;
+ return (
+ entity !== undefined &&
+ !isEmailEntity(entity) &&
+ deleteAction.canExecute(entity)
+ );
},
+ displayPriority: 10,
+ tags: [HotkeyTags.SelectionModification],
+ }).withGroup(group);
+
+ // An open email thread answers to '#' as its list does, so Trash is one
+ // keystroke whether the thread is a row or the thing being read. Unlike
+ // Backspace above, '#' costs an editor nothing: the reply composer is an
+ // editable input, where no hotkey runs.
+ registerHotkey({
+ hotkey: ['shift+3'],
+ hotkeyToken: TOKENS.email.trash,
+ scopeId,
+ description: 'Delete item',
+ keyDownHandler: runDelete,
condition: () => {
const entity = getEntity();
- return entity !== undefined && deleteAction.canExecute(entity);
+ return (
+ entity !== undefined &&
+ isEmailEntity(entity) &&
+ deleteAction.canExecute(entity)
+ );
},
displayPriority: 10,
tags: [HotkeyTags.SelectionModification],
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.ts
index 55ccdbd488..82317e4fa1 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
@@ -8,7 +8,7 @@ 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 EntityData, isTaskEntity } from '@entity';
+import { type EntityData, isEmailEntity, isTaskEntity } from '@entity';
import { SYSTEM_PROPERTY_IDS } from '@property/constants';
import type { Property, PropertyDefinitionDomain } from '@property/types';
import { type Accessor, onCleanup } from 'solid-js';
@@ -281,28 +281,56 @@ export const useEntityActionHotkeys = (
}).withGroup(group);
if (options.enableDeleteHotkey !== false) {
- // Delete - 'delete', 'backspace'
+ const deleteDescription = () => {
+ const count = getEntitiesForAction().length;
+ return count > 1 ? 'Delete items' : 'Delete item';
+ };
+ const runDelete = () => {
+ const entities = getEntitiesForAction();
+ if (entities.length === 0) return false;
+ if (!entities.every(deleteAction.canExecute)) return false;
+
+ deleteAction.executeWithSoup(entities, list);
+ return true;
+ };
+ const canDelete = () => {
+ if (condition && !condition()) return false;
+ const entities = getEntitiesForAction();
+ return entities.length > 0 && entities.every(deleteAction.canExecute);
+ };
+ const isEmailSelection = () => {
+ const entities = getEntitiesForAction();
+ return entities.length > 0 && entities.every(isEmailEntity);
+ };
+
+ // Delete - 'delete', 'backspace'. Registered as 'add' so it coexists on
+ // those keys with the email registration below rather than one eclipsing
+ // the other; their conditions are mutually exclusive, so exactly one of
+ // the two is ever live — and the command menu, which dedupes by
+ // description, shows a single Delete row with the key that applies.
registerHotkey({
hotkey: ['delete', 'backspace'],
hotkeyToken: TOKENS.entity.action.delete,
scopeId,
- description: () => {
- const count = getEntitiesForAction().length;
- return count > 1 ? 'Delete items' : 'Delete item';
- },
- keyDownHandler: () => {
- const entities = getEntitiesForAction();
- if (entities.length === 0) return false;
- if (!entities.every(deleteAction.canExecute)) return false;
+ description: deleteDescription,
+ keyDownHandler: runDelete,
+ condition: () => canDelete() && !isEmailSelection(),
+ registrationType: 'add',
+ displayPriority: 10,
+ tags: [HotkeyTags.SelectionModification],
+ }).withGroup(group);
- deleteAction.executeWithSoup(entities, list);
- return true;
- },
- condition: () => {
- if (condition && !condition()) return false;
- const entities = getEntitiesForAction();
- return entities.length > 0 && entities.every(deleteAction.canExecute);
- },
+ // Email selections also answer to '#', the key mail clients bind to
+ // Trash, so the same keystroke deletes a thread here and from inside an
+ // open thread. '#' arrives as 'shift+3' and prints back as '#'.
+ registerHotkey({
+ hotkey: ['shift+3', 'delete', 'backspace'],
+ hotkeyToken: TOKENS.email.trash,
+ scopeId,
+ description: deleteDescription,
+ keyDownHandler: runDelete,
+ condition: () => canDelete() && isEmailSelection(),
+ registrationType: 'add',
displayPriority: 10,
tags: [HotkeyTags.SelectionModification],
}).withGroup(group);
diff --git a/apps/web/src/features/settings/Shortcuts.tsx b/apps/web/src/features/settings/Shortcuts.tsx
index 5c48a72038..e0871fbab2 100644
--- a/apps/web/src/features/settings/Shortcuts.tsx
+++ b/apps/web/src/features/settings/Shortcuts.tsx
@@ -995,6 +995,11 @@ const shortcutSections: ShortcutSection[] = [
codes: ['ShiftLeft', 'KeyU'],
description: 'Mark read',
},
+ {
+ keys: ['#'],
+ codes: ['ShiftLeft', 'Digit3'],
+ description: 'Delete email',
+ },
],
},
];
diff --git a/apps/web/src/features/soup/createSoupEntityActions.ts b/apps/web/src/features/soup/createSoupEntityActions.ts
index 6c09a36146..44cbdaf1da 100644
--- a/apps/web/src/features/soup/createSoupEntityActions.ts
+++ b/apps/web/src/features/soup/createSoupEntityActions.ts
@@ -42,7 +42,7 @@ import { useUserId } from '@core/context/user';
import { type HotkeyToken, TOKENS } from '@core/hotkey/tokens';
import { isMobile } from '@core/mobile/isMobile';
import type { EntityData } from '@entity';
-import { isTaskEntity } from '@entity';
+import { isEmailEntity, isTaskEntity } from '@entity';
import { useSetCompanyHiddenMutation } from '@queries/crm/companies';
import type { Component, JSX } from 'solid-js';
@@ -527,7 +527,9 @@ export function createSoupEntityActions(): {
deleteItems.push({
id: 'delete',
label: 'Delete',
- hotkeyToken: TOKENS.entity.action.delete,
+ hotkeyToken: entities.every(isEmailEntity)
+ ? TOKENS.email.trash
+ : TOKENS.entity.action.delete,
onClick: handle(deleteAction.executeWithSoup),
destructive: true,
});
diff --git a/apps/web/src/lib/core/hotkey/tokens.ts b/apps/web/src/lib/core/hotkey/tokens.ts
index 32a8ce02d1..9317c9f3d4 100644
--- a/apps/web/src/lib/core/hotkey/tokens.ts
+++ b/apps/web/src/lib/core/hotkey/tokens.ts
@@ -148,6 +148,7 @@ export const TOKENS = {
previousMessage: 'email.previousMessage',
nextMessage: 'email.nextMessage',
cancelReply: 'email.cancelReply',
+ trash: 'email.trash',
blockSender: 'email.blockSender',
markSenderSignal: 'email.markSenderSignal',
markSenderNoise: 'email.markSenderNoise',
diff --git a/apps/web/src/lib/core/hotkey/utils.test.ts b/apps/web/src/lib/core/hotkey/utils.test.ts
index 1eace25334..bb17c1da9f 100644
--- a/apps/web/src/lib/core/hotkey/utils.test.ts
+++ b/apps/web/src/lib/core/hotkey/utils.test.ts
@@ -1,7 +1,12 @@
import { describe, expect, test } from 'vitest';
import type { HotkeyToken } from './tokens';
import type { HotkeyCommand } from './types';
-import { removeCommandsFromTokenMap } from './utils';
+import {
+ getKeyString,
+ normalizeEventKeyPress,
+ prettyPrintHotkeyString,
+ removeCommandsFromTokenMap,
+} from './utils';
const makeCommand = (token: HotkeyToken | undefined): HotkeyCommand =>
({
@@ -73,3 +78,18 @@ describe('removeCommandsFromTokenMap', () => {
expect(result.has('hotkey:b' as HotkeyToken)).toBe(false);
});
});
+
+// Shift punctuation is registered by the combination that produces it, so a
+// hotkey written as '#' would never match. Delete-email registers 'shift+3'.
+describe('shift punctuation round trip', () => {
+ test("a shifted '#' resolves to the 'shift+3' registration", () => {
+ const event = new KeyboardEvent('keydown', { key: '#', shiftKey: true });
+
+ expect(normalizeEventKeyPress(event)).toBe('3');
+ expect(getKeyString(new Set(['3', 'shift']))).toBe('shift+3');
+ });
+
+ test("'shift+3' displays as '#'", () => {
+ expect(prettyPrintHotkeyString('shift+3')).toBe('#');
+ });
+});
diff --git a/docs/AGENT_GUIDE/navigation.md b/docs/AGENT_GUIDE/navigation.md
index de160d2e14..6b189b0b1b 100644
--- a/docs/AGENT_GUIDE/navigation.md
+++ b/docs/AGENT_GUIDE/navigation.md
@@ -575,6 +575,9 @@ restart rules still apply.
- `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.
+- `#` — move email to Trash, with an Undo toast. Works on the selected or focused
+ rows in a mail list and on the thread open in an email detail or block. Email
+ only; other entity types keep Delete/Backspace and do not answer `#`.
- `g` then `h` — Home; `g` then `i` remains an alias.
- 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.