From 65a37318f0bcd4e2d7bc1be7d201bc052b5e4d43 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 19 Oct 2024 21:49:33 +0000 Subject: [PATCH] modified: index.html --- index.html | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index b3431f2..859e3cd 100644 --- a/index.html +++ b/index.html @@ -297,17 +297,23 @@ async function handleUserInput() { const chatBox = document.getElementById('chat-box'); chatBox.innerHTML += `

You: ${userInput}

`; - chatBox.innerHTML += `

AI: `; - const messageElement = chatBox.lastElementChild; + // Create a new paragraph for the AI response + const aiResponseParagraph = document.createElement('p'); + aiResponseParagraph.innerHTML = 'AI: '; + chatBox.appendChild(aiResponseParagraph); + + // Create a span element for the actual response content + const responseContent = document.createElement('span'); + aiResponseParagraph.appendChild(responseContent); let accumulatedContent = ''; for await (const chunk of sendMessage(userInput)) { accumulatedContent += chunk; const parsedChunk = marked.parse(accumulatedContent); - messageElement.innerHTML = parsedChunk; + responseContent.innerHTML = parsedChunk; // Apply syntax highlighting to code blocks - messageElement.querySelectorAll('pre code').forEach((block) => { + responseContent.querySelectorAll('pre code').forEach((block) => { hljs.highlightElement(block); }); } @@ -332,8 +338,8 @@ function initializeChatInterface() { }); } -document.getElementById("user-input").addEventListener("keypress", function(event) { - if (event.key === "Enter") { +document.getElementById("user-input").addEventListener("keydown", function(event) { + if (event.key === "Enter" && !event.shiftKey) { event.preventDefault(); handleUserInput(); }