π OpenHands: AI-Driven Development
fix: send on Enter for touchscreen laptops (#1418)
Vasco Schiavo1756d300563b
diff --git a/src/hooks/chat/use-chat-input-events.ts b/src/hooks/chat/use-chat-input-events.tsindex c57899faab..b9dde91024 100644--- a/src/hooks/chat/use-chat-input-events.ts+++ b/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/src/utils/utils.ts b/src/utils/utils.tsindex f9fe6f52a2..abccee6c81 100644--- a/src/utils/utils.ts+++ b/src/utils/utils.ts@@ -61,6 +61,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@@ -68,12 +79,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;