From 2966ad6ef6065447ba9d70a2d899c990d8f3fd22 Mon Sep 17 00:00:00 2001 From: DL Techy Date: Mon, 15 Jun 2026 14:34:24 +0800 Subject: [PATCH] fix(ui): Prevent Enter key from triggering submission on mobile devices (#3970) - Add check for mobile screen width (<= 768px) to prevent accidental submissions via the Enter key. - Update event listeners in static/app.js and static/js/chat.js to respect this constraint. --- static/app.js | 8 ++++++-- static/js/chat.js | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/static/app.js b/static/app.js index ed8b6e49a..684c5e9f4 100644 --- a/static/app.js +++ b/static/app.js @@ -3135,7 +3135,9 @@ function initializeEventListeners() { setTimeout(() => uiModule.autoResize(textarea), 1); }); textarea.addEventListener('keydown', (e) => { - if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) { + const isMobile = window.innerWidth <= 768 + + if (e.key === 'Enter' && !e.shiftKey && !e.isComposing && !isMobile) { // If ghost autocomplete is active, accept the suggestion instead of submitting if (window._ghostAutocomplete && window._ghostAutocomplete.isActive()) { e.preventDefault(); @@ -3708,7 +3710,9 @@ function startOdysseusApp() { // Enter to send (shift+enter for newline), or new chat when empty if (messageInput) { messageInput.addEventListener('keydown', (e) => { - if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) { + const isMobile = window.innerWidth <= 768 + + if (e.key === 'Enter' && !e.shiftKey && !e.isComposing && !isMobile) { e.preventDefault(); // Flush the debounced icon update so dataset.mode reflects the current // text state. Without this, a fast type-and-Enter would still see the diff --git a/static/js/chat.js b/static/js/chat.js index c510ebf92..c6d2652ab 100644 --- a/static/js/chat.js +++ b/static/js/chat.js @@ -3868,7 +3868,9 @@ import { wireArrowUpRecall, getLastUserMessageFromChatHistory } from './composer // Also submit on Enter (without shift) editor.addEventListener('keydown', (e) => { - if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) { + const isMobile = window.innerWidth <= 768 + + if (e.key === 'Enter' && !e.shiftKey && !e.isComposing && !isMobile) { e.preventDefault(); saveBtn.click(); }