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:
parent
66d0901938
commit
ae95b56465
|
|
@ -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)" 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>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -466,10 +466,9 @@ async function sendMessage() {
|
|||
updateSendBtn();
|
||||
}
|
||||
|
||||
let inputComposing = false;
|
||||
|
||||
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();
|
||||
sendMessage();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue