From f0ea48e09db55b6d90c5ee4cd4e418f502c8e969 Mon Sep 17 00:00:00 2001 From: G-Fourteen Date: Thu, 11 Sep 2025 15:18:09 -0600 Subject: [PATCH] feat: ensure enter to send across chat inputs --- chat-core.js | 26 +++++++++++++++++++------- chat-init.js | 9 +-------- simple.js | 17 +++++------------ 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/chat-core.js b/chat-core.js index d648d62..21d6009 100644 --- a/chat-core.js +++ b/chat-core.js @@ -13,19 +13,31 @@ async function pollinationsFetch(url, options = {}, { timeoutMs = 45000 } = {}) clearTimeout(timer); } } -window.pollinationsFetch = pollinationsFetch; - -// Load global AI instructions from external text file -window.aiInstructions = ""; +window.pollinationsFetch = pollinationsFetch; + +// Load global AI instructions from external text file +window.aiInstructions = ""; window.aiInstructionPromise = fetch("ai-instruct.txt") .then(res => res.text()) .then(text => { window.aiInstructions = text; }) .catch(err => { console.error("Failed to load AI instructions", err); window.aiInstructions = ""; - }); - -document.addEventListener("DOMContentLoaded", () => { + }); + +// Utility: allow Enter to send messages and Shift+Enter for new lines +window.setupEnterToSend = function(textarea, sendCallback) { + if (!textarea || typeof sendCallback !== "function") return; + textarea.addEventListener("keydown", (e) => { + const isEnter = e.key === "Enter" || e.keyCode === 13; + if (isEnter && !e.shiftKey) { + e.preventDefault(); + sendCallback(); + } + }); +}; + +document.addEventListener("DOMContentLoaded", () => { const chatBox = document.getElementById("chat-box"); const chatInput = document.getElementById("chat-input"); diff --git a/chat-init.js b/chat-init.js index cb0f082..535527d 100644 --- a/chat-init.js +++ b/chat-init.js @@ -571,15 +571,8 @@ document.addEventListener("DOMContentLoaded", () => { chatInput.style.height = chatInput.scrollHeight + "px"; }); sendButton.addEventListener("click", handleSendMessage); - // Send on Enter; newline with Shift+Enter - chatInput.addEventListener('keydown', (e) => { - const isEnter = e.key === 'Enter' || e.keyCode === 13; - if (isEnter && !e.shiftKey) { - e.preventDefault(); - handleSendMessage(); - } - }); + window.setupEnterToSend(chatInput, handleSendMessage); sendButton.disabled = chatInput.value.trim() === ""; chatInput.dispatchEvent(new Event("input")); const initialSession = Storage.getCurrentSession(); diff --git a/simple.js b/simple.js index 257567a..091abab 100644 --- a/simple.js +++ b/simple.js @@ -285,19 +285,12 @@ document.addEventListener("DOMContentLoaded", () => { }); }; simpleSendBtn.addEventListener("click", handleSimpleSend); - // Send on Enter; newline with Shift+Enter - simpleInput.addEventListener('keydown', (e) => { - const isEnter = e.key === 'Enter' || e.keyCode === 13; - if (isEnter && !e.shiftKey) { - e.preventDefault(); - handleSimpleSend(); - } - }); - - function appendSimpleMessage(role, content, index) { - const container = document.createElement("div"); - container.classList.add("simple-message"); + window.setupEnterToSend(simpleInput, handleSimpleSend); + + function appendSimpleMessage(role, content, index) { + const container = document.createElement("div"); + container.classList.add("simple-message"); container.dataset.index = index; container.dataset.role = role; if (role === "user") {