π OpenHands: AI-Driven Development
fix(frontend): send on Enter for touchscreen laptops (#14870)
Vasco Schiavo78e85b99d753
diff --git a/frontend/src/hooks/chat/use-chat-input-events.ts b/frontend/src/hooks/chat/use-chat-input-events.tsindex e6ae1bcc69..661f21aea2 100644--- a/frontend/src/hooks/chat/use-chat-input-events.ts+++ b/frontend/src/hooks/chat/use-chat-input-events.ts@@ -1,5 +1,5 @@import { useCallback } from "react";-import { isMobileDevice } from "#/utils/utils";+import { isMobileUserAgent } from "#/utils/utils";import {ensureCursorVisible,clearEmptyContent,@@ -80,8 +80,11 @@ export const useChatInputEvents = (return;}- // Original submit logic - only for desktop without shift key- if (!isMobileDevice() && !e.shiftKey && !disabled) {+ // Submit on Enter for everything except phones/tablets (where Enter+ // inserts a newline and the user taps the send button). We gate on the+ // user agent rather than touch capability so a desktop OS with a+ // touchscreen (e.g. a Windows 2-in-1) still submits on Enter.+ if (!isMobileUserAgent() && !e.shiftKey && !disabled) {e.preventDefault();handleSubmit();}diff --git a/frontend/src/utils/utils.ts b/frontend/src/utils/utils.tsindex bf9b3a71b3..dc900e5e8d 100644--- a/frontend/src/utils/utils.ts+++ b/frontend/src/utils/utils.ts@@ -55,6 +55,17 @@ export const setStyleHeightPx = (el: HTMLElement, height: number): void => {el.style.setProperty("height", `${height}px`);};+/**+ * Detect a phone/tablet user agent (Android, iPhone, iPad, β¦).+ * Unlike isMobileDevice, this ignores touch capability, so a desktop OS with+ * a touchscreen (e.g. a Windows 2-in-1) is NOT matched. Use this when the+ * decision depends on having a physical keyboard rather than on touch input.+ */+export const isMobileUserAgent = (): boolean =>+ /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(+ navigator.userAgent,+ );+/*** Detect if the user is on a mobile device.* Touch support alone is not sufficient β touchscreen laptops have touch@@ -62,12 +73,7 @@ export const setStyleHeightPx = (el: HTMLElement, height: number): void => {* pointing device is coarse (finger) to avoid false positives.*/export const isMobileDevice = (): boolean => {- if (- /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(- navigator.userAgent,- )- )- return true;+ if (isMobileUserAgent()) return true;const hasTouch = "ontouchstart" in window || navigator.maxTouchPoints > 0;if (!hasTouch) return false;