Skip to content

Your lightweight open-source personal agent.

feat(webui): newline instead of send on touch keyboards

moran2750a196017a
diff --git a/webui/src/components/thread/ThreadComposer.tsx b/webui/src/components/thread/ThreadComposer.tsx
index a09b77b9e..b5c484c6d 100644
--- a/webui/src/components/thread/ThreadComposer.tsx
+++ b/webui/src/components/thread/ThreadComposer.tsx
@@ -971,6 +971,9 @@ export function ThreadComposer({
const [recentSlashCommands, setRecentSlashCommands] = useState<string[]>(() => readSlashRecents());
const [queuedPrompts, setQueuedPrompts] = useState<QueuedPrompt[]>([]);
const hasTouchPrimaryPointer = useMediaQuery("(hover: none) and (pointer: coarse)");
+ // Wider than hasTouchPrimaryPointer on purpose: tablets with a physical
+ // keyboard still count as touch for the Enter key behavior below.
+ const hasCoarsePointer = useMediaQuery("(pointer: coarse)");
const textareaRef = useRef<HTMLTextAreaElement>(null);
const mentionOverlayRef = useRef<HTMLDivElement>(null);
const formRef = useRef<HTMLFormElement>(null);
@@ -2181,6 +2184,19 @@ export function ThreadComposer({
return;
}
}
+ // Touch keyboards: a plain Enter inserts a newline; sending stays on the
+ // send button. The select-on-Enter menu branches above take precedence.
+ if (
+ e.key === "Enter"
+ && !e.shiftKey
+ && !e.altKey
+ && !e.ctrlKey
+ && !e.metaKey
+ && !e.nativeEvent.isComposing
+ && hasCoarsePointer
+ ) {
+ return;
+ }
if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
e.preventDefault();
if (canQueueGuidance) {
@@ -2533,6 +2549,7 @@ export function ThreadComposer({
}}
onPaste={onPaste}
rows={1}
+ enterKeyHint={hasCoarsePointer ? "enter" : undefined}
placeholder={sessionDragPreview ? "" : resolvedPlaceholder}
disabled={interactionDisabled}
aria-label={inputAriaLabel ?? t("thread.composer.inputAria")}
diff --git a/webui/src/tests/thread-composer.test.tsx b/webui/src/tests/thread-composer.test.tsx
index d362b58b4..90f8dcdb7 100644
--- a/webui/src/tests/thread-composer.test.tsx
+++ b/webui/src/tests/thread-composer.test.tsx
@@ -1,4 +1,4 @@
-import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
+import { act, createEvent, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, describe, expect, it, vi } from "vitest";
@@ -347,6 +347,17 @@ function renderPresetComposer(
};
}
+function stubCoarsePointer(): void {
+ vi.stubGlobal("matchMedia", vi.fn((query: string) => ({
+ matches: query.includes("pointer: coarse"),
+ media: query,
+ onchange: null,
+ addEventListener: vi.fn(),
+ removeEventListener: vi.fn(),
+ dispatchEvent: vi.fn(),
+ })));
+}
+
describe("ThreadComposer", () => {
it("locks an async send and keeps the draft when it is rejected", async () => {
let resolveSend!: (accepted: boolean) => void;
@@ -407,6 +418,87 @@ describe("ThreadComposer", () => {
expect(input).not.toHaveFocus();
});
+ it("inserts a newline instead of sending on Enter on coarse-pointer devices", () => {
+ stubCoarsePointer();
+ const onSend = vi.fn();
+ render(
+ <ThreadComposer
+ onSend={onSend}
+ placeholder="Type your message..."
+ />,
+ );
+
+ const input = screen.getByLabelText("Message input");
+ fireEvent.change(input, { target: { value: "line one" } });
+ const keyEvent = createEvent.keyDown(input, { key: "Enter" });
+ fireEvent(input, keyEvent);
+
+ expect(keyEvent.defaultPrevented).toBe(false);
+ expect(onSend).not.toHaveBeenCalled();
+ });
+
+ it("keeps sending on Enter on precision-pointer devices", () => {
+ const onSend = vi.fn();
+ render(
+ <ThreadComposer
+ onSend={onSend}
+ placeholder="Type your message..."
+ />,
+ );
+
+ const input = screen.getByLabelText("Message input");
+ fireEvent.change(input, { target: { value: "desktop message" } });
+ fireEvent.keyDown(input, { key: "Enter" });
+
+ expect(onSend).toHaveBeenCalledWith("desktop message", undefined, undefined);
+ });
+
+ it("still selects a slash command with Enter on coarse-pointer devices", () => {
+ stubCoarsePointer();
+ const onSend = vi.fn();
+ render(
+ <ThreadComposer
+ onSend={onSend}
+ placeholder="Type your message..."
+ slashCommands={COMMANDS}
+ />,
+ );
+
+ const input = screen.getByLabelText("Message input");
+ fireEvent.change(input, { target: { value: "/" } });
+ expect(screen.getByRole("option", { name: /\/history/i })).toHaveAttribute(
+ "aria-selected",
+ "true",
+ );
+ fireEvent.keyDown(input, { key: "Enter" });
+
+ expect(input).toHaveValue("/history ");
+ expect(onSend).not.toHaveBeenCalled();
+ });
+
+ it("labels the keyboard action as enter on coarse-pointer devices", () => {
+ stubCoarsePointer();
+ render(
+ <ThreadComposer
+ onSend={vi.fn()}
+ placeholder="Type your message..."
+ />,
+ );
+
+ expect(screen.getByLabelText("Message input")).toHaveAttribute("enterkeyhint", "enter");
+ });
+
+ it("does not set enterkeyhint on precision-pointer devices", () => {
+ render(
+ <ThreadComposer
+ onSend={vi.fn()}
+ placeholder="Type your message..."
+ />,
+ );
+
+ expect(screen.getByLabelText("Message input")).not.toHaveAttribute("enterkeyhint");
+ });
+
it("focuses and sends a removable quoted answer excerpt", async () => {
const onSend = vi.fn();
const onQuotedContextChange = vi.fn();