diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index fd64c0226a..108354eea5 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -1464,18 +1464,8 @@ prompt = ''; const messages = createMessagesList(history, history.currentId); - - // Reset chat input textarea - if (!($settings?.richTextInput ?? true)) { - const chatInputElement = document.getElementById('chat-input'); - - if (chatInputElement) { - await tick(); - chatInputElement.style.height = ''; - } - } - const _files = JSON.parse(JSON.stringify(files)); + chatFiles.push(..._files.filter((item) => ['doc', 'file', 'collection'].includes(item.type))); chatFiles = chatFiles.filter( // Remove duplicates @@ -2378,11 +2368,7 @@ if (e.detail || files.length > 0) { await tick(); - submitPrompt( - ($settings?.richTextInput ?? true) - ? e.detail.replaceAll('\n\n', '\n') - : e.detail - ); + submitPrompt(e.detail.replaceAll('\n\n', '\n')); } }} /> @@ -2431,11 +2417,7 @@ clearDraft(); if (e.detail || files.length > 0) { await tick(); - submitPrompt( - ($settings?.richTextInput ?? true) - ? e.detail.replaceAll('\n\n', '\n') - : e.detail - ); + submitPrompt(e.detail.replaceAll('\n\n', '\n')); } }} /> diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index d24c5a5d2b..cd8ee35426 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -277,29 +277,8 @@ const chatInput = document.getElementById('chat-input'); if (chatInput) { - if ($settings?.richTextInput ?? true) { - chatInputElement.replaceVariables(variables); - chatInputElement.focus(); - } else { - // Get current value from the input element - let currentValue = chatInput.value || ''; - - // Replace template variables using regex - const updatedValue = currentValue.replace( - /{{\s*([^|}]+)(?:\|[^}]*)?\s*}}/g, - (match, varName) => { - const trimmedVarName = varName.trim(); - return variables.hasOwnProperty(trimmedVarName) - ? String(variables[trimmedVarName]) - : match; - } - ); - - // Update the input value - chatInput.value = updatedValue; - chatInput.focus(); - chatInput.dispatchEvent(new Event('input', { bubbles: true })); - } + chatInputElement.replaceVariables(variables); + chatInputElement.focus(); } }; @@ -309,16 +288,8 @@ if (chatInput) { text = await textVariableHandler(text || ''); - if ($settings?.richTextInput ?? true) { - chatInputElement?.setText(text); - chatInputElement?.focus(); - } else { - chatInput.value = text; - prompt = text; - - chatInput.focus(); - chatInput.dispatchEvent(new Event('input')); - } + chatInputElement?.setText(text); + chatInputElement?.focus(); text = await inputVariableHandler(text); await tick(); @@ -341,12 +312,7 @@ let word = ''; if (chatInput) { - if ($settings?.richTextInput ?? true) { - word = chatInputElement?.getWordAtDocPos(); - } else { - const cursor = chatInput ? chatInput.selectionStart : prompt.length; - word = getWordAtCursor(prompt, cursor); - } + word = chatInputElement?.getWordAtDocPos(); } return word; @@ -364,15 +330,7 @@ const chatInput = document.getElementById('chat-input'); if (!chatInput) return; - if ($settings?.richTextInput ?? true) { - chatInputElement?.replaceCommandWithText(text); - } else { - const cursor = chatInput.selectionStart; - const { start, end } = getWordBoundsAtCursor(prompt, cursor); - prompt = prompt.slice(0, start) + text + prompt.slice(end); - chatInput.focus(); - chatInput.setSelectionRange(start + text.length, start + text.length); - } + chatInputElement?.replaceCommandWithText(text); }; const insertTextAtCursor = async (text: string) => { @@ -384,14 +342,7 @@ if (command) { replaceCommandWithText(text); } else { - if ($settings?.richTextInput ?? true) { - chatInputElement?.insertContent(text); - } else { - const cursor = chatInput.selectionStart; - prompt = prompt.slice(0, cursor) + text + prompt.slice(cursor); - chatInput.focus(); - chatInput.setSelectionRange(cursor + text.length, cursor + text.length); - } + chatInputElement?.insertContent(text); } await tick(); @@ -413,18 +364,6 @@ if (words.length > 0) { const word = words.at(0); await tick(); - - if (!($settings?.richTextInput ?? true)) { - // Move scroll to the first word - chatInput.setSelectionRange(word.startIndex, word.endIndex + 1); - chatInput.focus(); - - const selectionRow = - (word?.startIndex - (word?.startIndex % chatInput.cols)) / chatInput.cols; - const lineHeight = chatInput.clientHeight / chatInput.rows; - - chatInput.scrollTop = lineHeight * selectionRow; - } } else { chatInput.scrollTop = chatInput.scrollHeight; } @@ -1230,12 +1169,12 @@ {/if}