Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions chat-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,26 @@ window.aiInstructionPromise = fetch("ai-instruct.txt")
// Utility: allow Enter to send messages and Shift+Enter for new lines
window.setupEnterToSend = function(textarea, sendCallback) {
if (!textarea || typeof sendCallback !== "function") return;
const handler = (e) => {

let composing = false;
textarea.addEventListener("compositionstart", () => { composing = true; });
textarea.addEventListener("compositionend", () => { composing = false; });

const onKeyDown = (e) => {
const key = e.key || e.keyCode;
const isEnter = key === "Enter" || key === 13;
if (isEnter && !e.shiftKey && !e.isComposing && !e.repeat) {

// Only send on plain Enter (no modifiers) and never while composing text
if (isEnter &&
!e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey &&
!composing && !e.repeat) {
e.preventDefault();
sendCallback();
}
};
textarea.addEventListener("keydown", handler);

// Capture = true to run before other bubbling listeners
textarea.addEventListener("keydown", onKeyDown, { capture: true });
};

document.addEventListener("DOMContentLoaded", () => {
Expand Down