diff --git a/components/contacts/__tests__/contacts-app.test.tsx b/components/contacts/__tests__/contacts-app.test.tsx index 830519bfd..a69a0e1d4 100644 --- a/components/contacts/__tests__/contacts-app.test.tsx +++ b/components/contacts/__tests__/contacts-app.test.tsx @@ -131,6 +131,21 @@ describe('ContactsApp', () => { expect(useContactStore.getState().selectedContactId).toBe('c-bob'); }); + it('adds the open contact to the selection on Ctrl+click, as Files does', () => { + renderContacts(); + fireEvent.click(screen.getByText('Alice Smith')); + fireEvent.click(screen.getByText('Bob Jones'), { ctrlKey: true }); + expect([...useContactStore.getState().selectedContactIds].sort()).toEqual(['c-alice', 'c-bob']); + }); + + it('selects from the open contact on Shift+click', () => { + const carol: ContactCard = { ...bob, id: 'c-carol', name: { full: 'Carol King' }, emails: { e0: { address: 'carol@example.com' } } }; + renderContacts([alice, bob, carol]); + fireEvent.click(screen.getByText('Bob Jones')); + fireEvent.click(screen.getByText('Carol King'), { shiftKey: true }); + expect([...useContactStore.getState().selectedContactIds].sort()).toEqual(['c-bob', 'c-carol']); + }); + it('leaves an untouched contact form without asking', () => { renderContacts(); fireEvent.click(screen.getByText('Alice Smith')); diff --git a/components/contacts/contact-list.tsx b/components/contacts/contact-list.tsx index 6833b8d1e..6f2304f2c 100644 --- a/components/contacts/contact-list.tsx +++ b/components/contacts/contact-list.tsx @@ -720,11 +720,17 @@ export function ContactList({ density={density} selectedContactIds={selectedContactIds} onClick={(e) => { + // The open contact counts as selected, as a clicked file does + // in Files: Ctrl/⌘+click and Shift+click build on it. + const startFromOpen = !hasSelection && !!selectedContactId + && selectedContactId !== contact.id && sortedIds.includes(selectedContactId); if (e.ctrlKey || e.metaKey) { e.preventDefault(); + if (startFromOpen) onToggleSelection(selectedContactId); onToggleSelection(contact.id); } else if (e.shiftKey) { e.preventDefault(); + if (startFromOpen) onToggleSelection(selectedContactId); onSelectRangeContacts(contact.id, sortedIds); } else { if (hasSelection) onClearSelection();