From 2c1408ea23c92a4f8b53aa6a9a3f2d2a626e0a48 Mon Sep 17 00:00:00 2001 From: G-Fourteen Date: Thu, 11 Sep 2025 14:46:30 -0600 Subject: [PATCH] Fix chat input handlers and network helper --- chat-core.js | 2 +- chat-init.js | 20 ++++++++++++-------- chat-storage.js | 24 ------------------------ 3 files changed, 13 insertions(+), 33 deletions(-) diff --git a/chat-core.js b/chat-core.js index cb7cbfb..d648d62 100644 --- a/chat-core.js +++ b/chat-core.js @@ -5,7 +5,7 @@ async function pollinationsFetch(url, options = {}, { timeoutMs = 45000 } = {}) try { const res = await fetch( url, - { ...options, signal: controller.signal, cache: 'no-store' } + { ...options, signal: controller.signal, cache: 'no-store' } // fixed: spread options ); if (!res.ok) throw new Error(`HTTP ${res.status}`); return res; diff --git a/chat-init.js b/chat-init.js index 17a429a..7a1d947 100644 --- a/chat-init.js +++ b/chat-init.js @@ -572,16 +572,20 @@ document.addEventListener("DOMContentLoaded", () => { }); sendButton.addEventListener("click", handleSendMessage); - // Send on Enter, allow newline with Shift+Enter + // Send on Enter; newline with Shift+Enter chatInput.addEventListener('keydown', (e) => { - if (e.key === 'Enter') { - if (e.shiftKey) return; // allow newline - e.preventDefault(); - // Directly invoke the send handler so the message is processed - // even if the button state would block programmatic clicks. - handleSendMessage(); + // IME safety and repeats + if (e.isComposing || e.key !== 'Enter') return; + + if (e.shiftKey) { + // allow newline + return; } - }); + + e.preventDefault(); + // Do not rely on button state—call the handler directly. + handleSendMessage(); + }, { once: false }); sendButton.disabled = chatInput.value.trim() === ""; chatInput.dispatchEvent(new Event("input")); const initialSession = Storage.getCurrentSession(); diff --git a/chat-storage.js b/chat-storage.js index 083982a..efe9589 100644 --- a/chat-storage.js +++ b/chat-storage.js @@ -602,30 +602,6 @@ document.addEventListener("DOMContentLoaded", () => { console.log("Click detected on image-button-container, preventing propagation"); } }, true); - const sendButton = document.getElementById("send-button"); - function handleSendMessage() { - const message = chatInput.value.trim(); - if (message === "") return; - window.addNewMessage({ role: "user", content: message }); - chatInput.value = ""; - chatInput.style.height = "auto"; - window.sendToPollinations(() => { - sendButton.disabled = false; - chatInput.disabled = false; - chatInput.focus(); - }); - sendButton.disabled = true; - chatInput.disabled = true; - } - chatInput.addEventListener("input", () => { - sendButton.disabled = chatInput.value.trim() === ""; - chatInput.style.height = "auto"; - chatInput.style.height = chatInput.scrollHeight + "px"; - }); - sendButton.addEventListener("click", () => { - handleSendMessage(); - }); - sendButton.disabled = chatInput.value.trim() === ""; const initialSession = Storage.getCurrentSession(); if (initialSession.messages && initialSession.messages.length > 0) { renderStoredMessages(initialSession.messages);