feat: replace keypress with isComposing

Ref: https://developer.mozilla.org/en-US/docs/Web/API/Element/keydown_event#keydown_events_with_ime
This commit is contained in:
SouthFox 2024-08-13 15:45:19 +08:00
parent 80726bbce9
commit 6c5e4e4bff

View file

@ -8,10 +8,8 @@ const sendButton = document.getElementById("sendButton");
const session_uuid = self.crypto.randomUUID(); const session_uuid = self.crypto.randomUUID();
sendButton.addEventListener("click", () => { sendButton.addEventListener("click", () => {
sendMessage(); sendMessage();
} });
);
promptInput.addEventListener("input", () => { promptInput.addEventListener("input", () => {
if (promptInput.value.split("\n").length == 1) { if (promptInput.value.split("\n").length == 1) {
@ -22,7 +20,7 @@ promptInput.addEventListener("input", () => {
} }
}); });
promptInput.addEventListener("keypress", () => { promptInput.addEventListener("keydown", () => {
handleKeyPress(event); handleKeyPress(event);
}); });
@ -107,6 +105,10 @@ function hideTypingIndicator() {
} }
function handleKeyPress(event) { function handleKeyPress(event) {
if (event.isComposing || event.keyCode === 229) {
return;
}
if (event.key == "Enter" && !event.shiftKey) { if (event.key == "Enter" && !event.shiftKey) {
event.preventDefault(); event.preventDefault();
sendMessage(); sendMessage();