From 57243142daf5bac9f249436bb26bf9475343fba5 Mon Sep 17 00:00:00 2001 From: FourWindff Date: Thu, 9 Jul 2026 22:52:16 +0800 Subject: [PATCH] fix(webui): send edited user message on Enter, keep Shift+Enter as newline The message edit textarea previously only submitted on Ctrl/Cmd+Enter, so both Enter and Shift+Enter inserted newlines. Align it with the composer behavior: Enter submits, Shift+Enter inserts a newline. Also guard against IME composition to avoid accidental submissions while selecting candidates. Co-Authored-By: Claude --- web/components/chat/home/ChatMessages.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/web/components/chat/home/ChatMessages.tsx b/web/components/chat/home/ChatMessages.tsx index cb24a3e61..161dbe841 100644 --- a/web/components/chat/home/ChatMessages.tsx +++ b/web/components/chat/home/ChatMessages.tsx @@ -51,6 +51,7 @@ import type { StreamEvent } from "@/lib/unified-ws"; import { hasVisibleMarkdownContent } from "@/lib/markdown-display"; import type { SelectedBookReference } from "@/lib/book-references"; import { buildVisiblePath, type SiblingInfo } from "@/lib/message-branches"; +import { shouldSubmitOnEnter } from "@/lib/composer-keyboard"; import type { SpaceMemoryFile } from "@/lib/space-items"; import { AskUserOptions, @@ -876,6 +877,7 @@ const UserMessage = memo(function UserMessage({ const { t } = useTranslation(); const [editing, setEditing] = useState(false); const [draft, setDraft] = useState(msg.content); + const isComposingRef = useRef(false); // Connected subagents ride in knowledge_bases (same selection path) but are // agents, not KBs — this maps a selected name to its backend kind so the // reference chip can badge it with the agent's brand icon. @@ -1035,8 +1037,21 @@ const UserMessage = memo(function UserMessage({ } else if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) { e.preventDefault(); submitEdit(); + } else if (shouldSubmitOnEnter(e, isComposingRef.current)) { + e.preventDefault(); + submitEdit(); } }} + onCompositionStart={() => { + isComposingRef.current = true; + }} + onCompositionEnd={() => { + // Some IMEs fire compositionend before the Enter keydown that confirms + // a candidate, so keep the guard through the current event turn. + setTimeout(() => { + isComposingRef.current = false; + }, 0); + }} rows={Math.min(8, Math.max(2, draft.split("\n").length))} className="w-full resize-none border-0 bg-transparent text-[14px] leading-relaxed text-[var(--foreground)] outline-none focus:outline-none" />