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.

Do not send AI/agent messages from Enter on touch devices (#7241)

teo39c13f9ba9db
diff --git a/apps/web/src/features/agents-view/components/ChatComposer.test.tsx b/apps/web/src/features/agents-view/components/ChatComposer.test.tsx
index 684fdbbc8f..5c61b1095b 100644
--- a/apps/web/src/features/agents-view/components/ChatComposer.test.tsx
+++ b/apps/web/src/features/agents-view/components/ChatComposer.test.tsx
@@ -1,4 +1,5 @@
import type { InputAttachmentData } from '@channel/Input/types';
+import { isTouchDevice } from '@core/mobile/isTouchDevice';
import { $createQuoteNode, QuoteNode } from '@lexical/rich-text';
import { fireEvent, render, screen } from '@solidjs/testing-library';
import {
@@ -12,6 +13,10 @@ import { createSignal } from 'solid-js';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { ChatComposer, ChatSessionInput } from './ChatComposer';
+vi.mock('@core/mobile/isTouchDevice', () => ({
+ isTouchDevice: vi.fn(() => false),
+}));
+
const editor = vi.hoisted(() => ({
lexical: undefined as LexicalEditor | undefined,
clear: vi.fn(),
@@ -121,6 +126,7 @@ beforeEach(() => {
}
);
vi.clearAllMocks();
+ vi.mocked(isTouchDevice).mockReturnValue(false);
editor.text = '';
editor.enter = undefined;
editor.change = undefined;
@@ -183,6 +189,56 @@ describe('Chat session input', () => {
expect(stop).toHaveBeenCalledOnce();
});
+ describe('on a touch device', () => {
+ beforeEach(() => {
+ vi.mocked(isTouchDevice).mockReturnValue(true);
+ });
+
+ it('leaves Enter to the virtual keyboard and sends only from the button', () => {
+ const send = vi.fn();
+ render(() => <ChatSessionInput onSend={send} />);
+ type('first line');
+ // Not captured, so the editor inserts a newline instead of sending.
+ expect(editor.enter?.(undefined, editor.text)).toBe(false);
+ expect(send).not.toHaveBeenCalled();
+ expect(editor.clear).not.toHaveBeenCalled();
+ fireEvent.click(screen.getByRole('button', { name: 'Send' }));
+ expect(send).toHaveBeenCalledWith('first line', []);
+ });
+
+ it('does not advance the queue from Enter either', () => {
+ const stop = vi.fn();
+ render(() => (
+ <ChatSessionInput
+ busy
+ hasQueuedMessages
+ onSend={vi.fn()}
+ onStop={stop}
+ />
+ ));
+ expect(editor.enter?.(undefined, '')).toBe(false);
+ expect(stop).not.toHaveBeenCalled();
+ fireEvent.click(
+ screen.getByRole('button', { name: 'Send next queued message' })
+ );
+ expect(stop).toHaveBeenCalledOnce();
+ });
+
+ it('applies to a new conversation as well', () => {
+ const send = vi.fn();
+ render(() => (
+ <ChatComposer
+ draft="Describe this"
+ onDraftChange={vi.fn()}
+ selector={null}
+ onSend={send}
+ />
+ ));
+ expect(editor.enter?.(undefined, 'Describe this')).toBe(false);
+ expect(send).not.toHaveBeenCalled();
+ });
+ });
+
it('registers and cleans up session focus and quote handlers', () => {
const focus = vi.fn();
const quote = vi.fn();
diff --git a/apps/web/src/features/agents-view/components/ChatComposer.tsx b/apps/web/src/features/agents-view/components/ChatComposer.tsx
index fbe687d40c..ff4d785a4b 100644
--- a/apps/web/src/features/agents-view/components/ChatComposer.tsx
+++ b/apps/web/src/features/agents-view/components/ChatComposer.tsx
@@ -101,6 +101,9 @@ export function ChatComposer(props: {
},
})
.onEnter((_event, markdown) => {
+ // On a virtual keyboard Enter is a newline, as in channels; the send
+ // button is the only way to submit.
+ if (isTouchDevice()) return false;
if (markdown.trim() || attachments().length > 0) send(markdown);
else if (canSendNext()) sendNext();
return true;
diff --git a/apps/web/src/features/block-agent/ui/AgentInput.test.tsx b/apps/web/src/features/block-agent/ui/AgentInput.test.tsx
index c63a0eca87..7d77b60c85 100644
--- a/apps/web/src/features/block-agent/ui/AgentInput.test.tsx
+++ b/apps/web/src/features/block-agent/ui/AgentInput.test.tsx
@@ -10,10 +10,15 @@ import {
* @vitest-environment jsdom
*/
+import { isTouchDevice } from '@core/mobile/isTouchDevice';
import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { AGENT_INPUT_TEXT_AREA_ID, AgentInput } from './AgentInput';
+vi.mock('@core/mobile/isTouchDevice', () => ({
+ isTouchDevice: vi.fn(() => false),
+}));
+
const editor = vi.hoisted(() => ({
lexical: undefined as LexicalEditor | undefined,
clear: vi.fn(),
@@ -112,6 +117,43 @@ beforeEach(() => {
editor.clear.mockClear();
editor.enter = undefined;
editor.change = undefined;
+ vi.mocked(isTouchDevice).mockReturnValue(false);
+});
+
+describe('on a touch device', () => {
+ beforeEach(() => {
+ vi.mocked(isTouchDevice).mockReturnValue(true);
+ });
+
+ it('leaves Enter to the virtual keyboard and sends only from the button', () => {
+ const onSend = vi.fn();
+ render(() => <AgentInput onSend={onSend} />);
+
+ editor.change?.('first line');
+ // Not captured, so the editor inserts a newline instead of sending.
+ expect(editor.enter?.()).toBe(false);
+ expect(onSend).not.toHaveBeenCalled();
+ expect(editor.clear).not.toHaveBeenCalled();
+
+ fireEvent.click(screen.getByRole('button', { name: 'Send' }));
+ expect(onSend).toHaveBeenCalledWith('first line', []);
+ expect(editor.clear).toHaveBeenCalledOnce();
+ });
+
+ it('does not advance the queue from Enter either', () => {
+ const onStop = vi.fn();
+ render(() => (
+ <AgentInput busy hasQueuedMessages onSend={vi.fn()} onStop={onStop} />
+ ));
+
+ expect(editor.enter?.()).toBe(false);
+ expect(onStop).not.toHaveBeenCalled();
+
+ fireEvent.click(
+ screen.getByRole('button', { name: 'Send next queued message' })
+ );
+ expect(onStop).toHaveBeenCalledOnce();
+ });
});
describe('queued message advancement', () => {
diff --git a/apps/web/src/features/block-agent/ui/AgentInput.tsx b/apps/web/src/features/block-agent/ui/AgentInput.tsx
index 2153f1f12f..af21693b29 100644
--- a/apps/web/src/features/block-agent/ui/AgentInput.tsx
+++ b/apps/web/src/features/block-agent/ui/AgentInput.tsx
@@ -218,6 +218,9 @@ export function AgentInput(props: AgentInputProps) {
},
})
.onEnter(() => {
+ // On a virtual keyboard Enter is a newline, as in channels; the send
+ // button is the only way to submit.
+ if (isTouchDevice()) return false;
if (canSend()) send();
else sendNext();
return true;
diff --git a/apps/web/src/lib/core/component/AI/component/input/ChatInput.test.tsx b/apps/web/src/lib/core/component/AI/component/input/ChatInput.test.tsx
index b7eeb65a22..9df37dad80 100644
--- a/apps/web/src/lib/core/component/AI/component/input/ChatInput.test.tsx
+++ b/apps/web/src/lib/core/component/AI/component/input/ChatInput.test.tsx
@@ -7,6 +7,7 @@ import { ChatInput } from './ChatInput';
const mocks = vi.hoisted(() => ({
touch: true,
emitChange: undefined as ((value: string) => void) | undefined,
+ enter: undefined as ((event?: KeyboardEvent) => boolean) | undefined,
root: undefined as HTMLDivElement | undefined,
upload: vi.fn(),
mount: vi.fn(),
@@ -135,6 +136,7 @@ afterEach(() => {
mocks.touch = true;
mocks.root = undefined;
mocks.emitChange = undefined;
+ mocks.enter = undefined;
vi.clearAllMocks();
});
@@ -144,7 +146,10 @@ function setup(collapseOnBlur = true) {
const editor = {
buildHandle: () => ({ lexical: {} }),
withFilePaste: () => editor,
- onEnter: () => editor,
+ onEnter: (callback: (event?: KeyboardEvent) => boolean) => {
+ mocks.enter = callback;
+ return editor;
+ },
onEscape: () => editor,
onChange: (callback: (value: string) => void) => {
mocks.emitChange = callback;
@@ -251,6 +256,28 @@ describe('compact mobile chat drafts', () => {
});
});
+describe('Enter', () => {
+ it('is left to the virtual keyboard on touch devices, so only the button sends', () => {
+ const { draft, onSend } = setup();
+ // Not captured, so the editor inserts a newline instead of sending.
+ expect(mocks.enter?.()).toBe(false);
+ expect(onSend).not.toHaveBeenCalled();
+ fireEvent.click(screen.getByRole('button', { name: 'Send' }));
+ expect(onSend).toHaveBeenCalledWith(
+ expect.objectContaining({ content: draft })
+ );
+ });
+
+ it('sends on desktop', () => {
+ mocks.touch = false;
+ const { draft, onSend } = setup();
+ expect(mocks.enter?.()).toBe(true);
+ expect(onSend).toHaveBeenCalledWith(
+ expect.objectContaining({ content: draft })
+ );
+ });
+});
+
it.each([true, false])(
'opens the device file picker directly and uploads selected files (touch=%s)',
(touch) => {
diff --git a/apps/web/src/lib/core/component/AI/component/input/ChatInput.tsx b/apps/web/src/lib/core/component/AI/component/input/ChatInput.tsx
index d35db0ffbf..d4358d22d6 100644
--- a/apps/web/src/lib/core/component/AI/component/input/ChatInput.tsx
+++ b/apps/web/src/lib/core/component/AI/component/input/ChatInput.tsx
@@ -223,6 +223,9 @@ export function ChatInput(props: ChatInputComponentProps) {
},
})
.onEnter((e) => {
+ // On a virtual keyboard Enter is a newline, as in channels; the send
+ // button is the only way to submit.
+ if (isTouchDevice()) return false;
if (canSendMessage()) {
sendMessage({ metaKey: e?.metaKey });
}
diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.md
index 0d282bc083..c052f043ee 100644
--- a/docs/AGENT_GUIDE/ai-chat.md
+++ b/docs/AGENT_GUIDE/ai-chat.md
@@ -268,6 +268,7 @@ is available, the AI composer returns with its draft intact, including in
documents without a comment composer. Type a
prompt, optionally choose a model or
attach context, and tap **Send** to create the chat and send its first message.
+Enter on the virtual keyboard adds a line to the draft rather than sending it.
The paperclip (**Attach files**) opens the device file chooser directly, including
in the native iPhone app; it does not open a Macro file browser. Select supported
files to upload and attach them, or cancel to return to the unchanged draft.
@@ -570,7 +571,11 @@ On mobile the composer (and any queued prompts above it) floats in the bottom
accessory region above the dock — same placement as channel and AI chat — so it
stays tappable and clear of the home indicator. The box is full width; the text
sits on top and a footer row holds the model (left, as a provider logo and
-name, e.g. `✳ Sonnet 5 ⌄`) and **Send** (right). Tapping the model opens a
+name, e.g. `✳ Sonnet 5 ⌄`) and **Send** (right). On touch devices Enter on the
+virtual keyboard inserts a newline and never sends; only **Send** submits, the
+same as channel composers. This also applies to the Agents workspace session
+and new-conversation inputs and to the mobile **Ask AI** composer. On desktop
+Enter still sends and Shift+Enter inserts a newline. Tapping the model opens a
bottom sheet listing every model the same way, with a check on the current one
— pick a row to switch. Models read as names even when the runtime reports
only ids: Macro Agent's `anthropic/claude-sonnet-5` shows as **Sonnet 5**. On desktop the