Timothy Jaeryang Baek 3 months ago
parent
commit
b612af29e9
1 changed files with 18 additions and 1 deletions
  1. 18 1
      src/lib/components/chat/MessageInput/Commands/Prompts.svelte

+ 18 - 1
src/lib/components/chat/MessageInput/Commands/Prompts.svelte

@@ -152,7 +152,24 @@
 			chatInputElement.focus();
 			chatInputElement.dispatchEvent(new Event('input'));
 
-			chatInputElement.scrollTop = chatInputElement.scrollHeight;
+			const words = extractCurlyBraceWords(prompt);
+
+			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;
+
+				prompt = fullPrompt;
+				await tick();
+
+				chatInputElement.setSelectionRange(word?.startIndex, word.endIndex + 1);
+			} else {
+				chatInputElement.scrollTop = chatInputElement.scrollHeight;
+			}
 		}
 	};
 </script>