fix: prevent Enter from submitting during IME composition

Added compositionstart/compositionend event listeners to track IME
composing state. Enter key now only submits when not composing,
so Chinese/Japanese/Korean input methods work correctly.
This commit is contained in:
chiguyong 2026-06-11 15:37:06 +08:00
parent cc4c6fe346
commit 66d0901938
1 changed files with 4 additions and 2 deletions

View File

@ -211,7 +211,7 @@ html,body{height:100%;font-family:var(--font);background:var(--bg);color:var(--t
</div>
<div class="input-area">
<div class="input-wrap">
<textarea id="input" rows="1" placeholder="输入消息..." onkeydown="handleKey(event)" oninput="autoResize(this)"></textarea>
<textarea id="input" rows="1" placeholder="输入消息..." onkeydown="handleKey(event)" oninput="autoResize(this)" oncompositionstart="inputComposing=true" oncompositionend="inputComposing=false"></textarea>
<button class="btn-send" id="sendBtn" onclick="sendMessage()">发送</button>
</div>
</div>
@ -466,8 +466,10 @@ async function sendMessage() {
updateSendBtn();
}
let inputComposing = false;
function handleKey(e) {
if (e.key === 'Enter' && !e.shiftKey) {
if (e.key === 'Enter' && !e.shiftKey && !inputComposing) {
e.preventDefault();
sendMessage();
}