From 6c5e4e4bff1352d48dcd0bed66fbc6f30ea51bd2 Mon Sep 17 00:00:00 2001 From: SouthFox Date: Tue, 13 Aug 2024 15:45:19 +0800 Subject: [PATCH] feat: replace keypress with isComposing Ref: https://developer.mozilla.org/en-US/docs/Web/API/Element/keydown_event#keydown_events_with_ime --- static/script.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/static/script.js b/static/script.js index 72221c7..8b68b5e 100644 --- a/static/script.js +++ b/static/script.js @@ -8,10 +8,8 @@ const sendButton = document.getElementById("sendButton"); const session_uuid = self.crypto.randomUUID(); sendButton.addEventListener("click", () => { - sendMessage(); -} -); - + sendMessage(); +}); promptInput.addEventListener("input", () => { if (promptInput.value.split("\n").length == 1) { @@ -22,7 +20,7 @@ promptInput.addEventListener("input", () => { } }); -promptInput.addEventListener("keypress", () => { +promptInput.addEventListener("keydown", () => { handleKeyPress(event); }); @@ -107,6 +105,10 @@ function hideTypingIndicator() { } function handleKeyPress(event) { + if (event.isComposing || event.keyCode === 229) { + return; + } + if (event.key == "Enter" && !event.shiftKey) { event.preventDefault(); sendMessage();