Timothy Jaeryang Baek 3 mēneši atpakaļ
vecāks
revīzija
75096c24ac

+ 6 - 6
src/lib/components/admin/Functions.svelte

@@ -288,21 +288,21 @@
 			>
 
 			<button
-				class="min-w-fit p-1.5 {selectedType === 'filter'
+				class="min-w-fit p-1.5 {selectedType === 'pipe'
 					? ''
 					: 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition"
 				on:click={() => {
-					selectedType = 'filter';
-				}}>{$i18n.t('Filter')}</button
+					selectedType = 'pipe';
+				}}>{$i18n.t('Pipe')}</button
 			>
 
 			<button
-				class="min-w-fit p-1.5 {selectedType === 'pipe'
+				class="min-w-fit p-1.5 {selectedType === 'filter'
 					? ''
 					: 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition"
 				on:click={() => {
-					selectedType = 'pipe';
-				}}>{$i18n.t('Pipe')}</button
+					selectedType = 'filter';
+				}}>{$i18n.t('Filter')}</button
 			>
 
 			<button

+ 7 - 8
src/lib/components/chat/MessageInput/Commands/Prompts.svelte

@@ -175,17 +175,16 @@
 
 			if (words.length > 0) {
 				const word = words.at(0);
-				const fullPrompt = prompt;
-
-				prompt = prompt.substring(0, word?.endIndex + 1);
 				await tick();
 
-				chatInputElement.scrollTop = chatInputElement.scrollHeight;
+				if (!($settings?.richTextInput ?? true)) {
+					chatInputElement.setSelectionRange(word.startIndex, word.endIndex + 1);
+					chatInputElement.focus();
 
-				prompt = fullPrompt;
-				await tick();
-
-				chatInputElement.setSelectionRange(word?.startIndex, word.endIndex + 1);
+					// This is a workaround to ensure the cursor is placed correctly
+					// after the text is inserted, especially for multiline inputs.
+					chatInputElement.setSelectionRange(word.startIndex, word.endIndex + 1);
+				}
 			} else {
 				chatInputElement.scrollTop = chatInputElement.scrollHeight;
 			}

+ 5 - 0
src/lib/components/common/RichTextInput.svelte

@@ -123,6 +123,11 @@
 			if (dispatch) {
 				const tr = state.tr.setSelection(TextSelection.create(doc, template.from, template.to));
 				dispatch(tr);
+
+				// Scroll to the selected template
+				dispatch(
+					tr.scrollIntoView().setMeta('preventScroll', true) // Prevent default scrolling behavior
+				);
 			}
 			return true;
 		}