Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

fix(console): ⌘↩ in the participant field confirms, and picks hold while adding

raullopez-sandbox3ab348716e08
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-name-input.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-name-input.tsx
index e6815e156..3c30fabad 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-name-input.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-name-input.tsx
@@ -22,7 +22,8 @@ export function RoomNameInput({
onKeyDown={(e) => {
// keyCode 229: a key the IME is handling, which some IMEs send with isComposing false.
if (e.nativeEvent.isComposing || e.keyCode === 229) return;
- if (e.key === 'Enter') onSubmit();
+ // ⌘↩ / Ctrl+↩ is the dialog's own confirm; answering it here too would submit twice.
+ if (e.key === 'Enter' && !e.metaKey && !e.ctrlKey) onSubmit();
}}
/>
);
diff --git a/console/apps/switch-console-desktop/src/renderer/lib/components/participant-picker.tsx b/console/apps/switch-console-desktop/src/renderer/lib/components/participant-picker.tsx
index 9af729cfb..33bab8c52 100644
--- a/console/apps/switch-console-desktop/src/renderer/lib/components/participant-picker.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/lib/components/participant-picker.tsx
@@ -45,10 +45,12 @@ export function ParticipantChip({
participant,
serverId,
onRemove,
+ disabled,
}: {
participant: Participant;
serverId: string | null;
onRemove: () => void;
+ disabled: boolean;
}) {
const accent = useAgentAccent(participant.kind === 'agent' ? participant : null, serverId);
return (
@@ -66,8 +68,9 @@ export function ParticipantChip({
<button
type="button"
aria-label={`Remove ${participant.name}`}
+ disabled={disabled}
onClick={onRemove}
- className="flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-full text-foreground-muted hover:bg-[var(--sel-soft)] hover:text-foreground"
+ className="flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-full text-foreground-muted hover:bg-[var(--sel-soft)] hover:text-foreground disabled:cursor-wait disabled:opacity-50"
>
<X className="size-3" />
</button>
@@ -132,6 +135,8 @@ export function ParticipantPicker({
participant={participant}
serverId={serverId}
onRemove={() => onChange(picked.filter((each) => each !== participant))}
+ // The picks are being applied as they stand; changing them now would change nothing.
+ disabled={busy}
/>
))}
<input
@@ -157,6 +162,8 @@ export function ParticipantPicker({
onKeyDown={(event) => {
// keyCode 229: a key the IME is handling, which some IMEs send with isComposing false.
if (event.nativeEvent.isComposing || event.keyCode === 229) return;
+ // ⌘↩ / Ctrl+↩ confirms the form around the field; it is not a pick.
+ if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) return;
const action = pickerKey(event.key, {
query,
open,
@@ -171,8 +178,9 @@ export function ParticipantPicker({
setOpen(true);
setActive(action.active);
} else if (action.type === 'add') add(results[current]);
- else if (action.type === 'removeLast') onChange(picked.slice(0, -1));
- else setOpen(false);
+ else if (action.type === 'removeLast') {
+ if (!busy) onChange(picked.slice(0, -1));
+ } else setOpen(false);
}}
/>
{busy && (
diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/new-room-ime.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/new-room-ime.test.tsx
index 82f844460..37a685d4a 100644
--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/new-room-ime.test.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/new-room-ime.test.tsx
@@ -10,6 +10,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
import { RoomNameInput } from '@renderer/features/switch-servers/room-name-input';
import { ParticipantPicker } from '@renderer/lib/components/participant-picker';
import type { Participant } from '@renderer/lib/components/participant-search';
+import { ConfirmButton } from '@renderer/lib/ui/confirm-button';
let container: HTMLDivElement | null = null;
let root: Root | null = null;
@@ -78,6 +79,9 @@ describe('New room IME', () => {
expect(onSubmit).not.toHaveBeenCalled();
await act(async () => enter(input, { keyCode: 13 }));
expect(onSubmit).toHaveBeenCalledTimes(1);
+ // ⌘↩ is left to the dialog's confirm button.
+ await act(async () => enter(input, { keyCode: 13, metaKey: true, ctrlKey: true }));
+ expect(onSubmit).toHaveBeenCalledTimes(1);
});
});
@@ -148,3 +152,70 @@ describe('Participant field results', () => {
}
});
});
+
+describe('Participant field with a confirm button', () => {
+ const smiley: Participant = { ...helper, id: 'a2', name: 'smiley' };
+ const mod = navigator.platform.toLowerCase().includes('mac')
+ ? { metaKey: true }
+ : { ctrlKey: true };
+
+ it('lets ⌘↩ confirm the picks instead of taking the highlighted result', async () => {
+ const submitted: string[][] = [];
+ function Harness() {
+ const [picked, setPicked] = useState<Participant[]>([]);
+ return (
+ <>
+ <ParticipantPicker
+ candidates={[helper, smiley]}
+ picked={picked}
+ onChange={setPicked}
+ serverId={null}
+ loading={false}
+ inputId="confirm"
+ autoFocus={false}
+ busy={false}
+ overlay
+ />
+ <ConfirmButton onClick={() => submitted.push(picked.map((each) => each.id))}>
+ Add
+ </ConfirmButton>
+ </>
+ );
+ }
+ const input = await render(<Harness />);
+ await act(async () => input.focus());
+ await act(async () => enter(input, { keyCode: 13 }));
+ // The results are open again on smiley.
+ expect(container!.querySelector('[role="listbox"]')).not.toBeNull();
+ await act(async () => enter(input, { keyCode: 13, ...mod }));
+ expect(submitted).toEqual([['a1']]);
+ expect(container!.querySelectorAll('[aria-label^="Remove"]')).toHaveLength(1);
+ });
+
+ it('keeps the picks as they are while they are being added', async () => {
+ const onChange = vi.fn();
+ const input = await render(
+ <ParticipantPicker
+ candidates={[helper, smiley]}
+ picked={[helper, smiley]}
+ onChange={onChange}
+ serverId={null}
+ loading={false}
+ inputId="busy"
+ autoFocus={false}
+ busy
+ overlay
+ />
+ );
+ await act(async () => input.focus());
+ await act(async () =>
+ input.dispatchEvent(
+ new KeyboardEvent('keydown', { key: 'Backspace', bubbles: true, cancelable: true })
+ )
+ );
+ const remove = container!.querySelector<HTMLButtonElement>('[aria-label="Remove smiley"]')!;
+ expect(remove.disabled).toBe(true);
+ await act(async () => remove.click());
+ expect(onChange).not.toHaveBeenCalled();
+ });
+});