fix: add the open contact to the selection on Ctrl+click and Shift+click in Contacts

This commit is contained in:
Linus Rath
2026-10-28 10:14:19 +01:00
parent bae76bcc4e
commit cb4f4c9168
2 changed files with 21 additions and 0 deletions
@@ -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'));
+6
View File
@@ -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();