fix: use e.isComposing for IME detection instead of manual flag

e.isComposing is a standard KeyboardEvent property that's true during
IME composition. More reliable than compositionstart/compositionend
which can fire at unpredictable timing relative to keydown.
This commit is contained in:
chiguyong 2026-06-11 20:43:38 +08:00
parent 66d0901938
commit ae95b56465
1 changed files with 3 additions and 4 deletions

View File

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