diff --git a/Components/ChatInput.svelte b/Components/ChatInput.svelte new file mode 100644 index 0000000..decef3e --- /dev/null +++ b/Components/ChatInput.svelte @@ -0,0 +1,211 @@ + + +
+
+
+ + + + +
+ + diff --git a/Components/ChatWindow.svelte b/Components/ChatWindow.svelte index aef8d56..4453b20 100644 --- a/Components/ChatWindow.svelte +++ b/Components/ChatWindow.svelte @@ -2,8 +2,8 @@ import { Resolve } from "Services/DependencyService"; import { Services } from "Services/Services"; import ChatArea from "./ChatArea.svelte"; + import ChatInput from "./ChatInput.svelte"; import { tick, onMount } from "svelte"; - import { setIcon } from "obsidian"; import { conversationStore } from "../Stores/conversationStore"; import { Conversation } from "Conversations/Conversation"; import type AIAgentPlugin from "main"; @@ -18,13 +18,10 @@ let workSpaceService: WorkSpaceService = Resolve(Services.WorkSpaceService); let conversationService: ConversationFileSystemService = Resolve(Services.ConversationFileSystemService); - let textareaElement: HTMLDivElement; let chatContainer: HTMLDivElement; - let submitButton: HTMLButtonElement; - let editModeButton: HTMLButtonElement; let chatArea: ChatArea; + let chatInput: ChatInput; - let userRequest = ""; let hasNoApiKey = false; let isSubmitting = false; let editModeActive = false; @@ -35,9 +32,7 @@ let currentThought: string | null = null; export function focusInput() { - tick().then(() => { - textareaElement?.focus(); - }); + chatInput?.focusInput(); } export function resetChatArea() { @@ -92,22 +87,15 @@ chatArea.scrollChatArea("smooth"); } - async function handleSubmit() { + async function handleSubmit(userRequest: string) { focusInput(); if (handleNoApiKey()) { return; } - if (userRequest.trim() === "" || isSubmitting) { - return; - } - const currentRequest = userRequest; - textareaElement.textContent = ""; - userRequest = ""; - await chatService.submit(conversation, editModeActive, currentRequest, { onSubmit: () => { chatArea.scrollChatArea("smooth"); @@ -128,34 +116,6 @@ }); } - function handleKeydown(e: KeyboardEvent) { - if (e.key === 'Enter') { - if (e.shiftKey) { - return; - } else { - e.preventDefault(); - handleSubmit(); - } - } - } - - function handleInput() { - if (textareaElement) { - userRequest = textareaElement.textContent || ""; - if (userRequest.trim() === "") { - textareaElement.textContent = ""; - } - } - } - - $: if (submitButton) { - setIcon(submitButton, isSubmitting ? "square" : "send-horizontal"); - } - - $: if (editModeButton) { - setIcon(editModeButton, editModeActive ? "pencil" : "pencil-off"); - } - $: if ($conversationStore.shouldReset) { conversation = new Conversation(); chatService.setStatusBarTokens(0, 0); @@ -190,40 +150,16 @@ - -
-
-
- - - -
+ \ No newline at end of file