diff --git a/Components/ChatWindow.svelte b/Components/ChatWindow.svelte index 2fbbf87..9a35569 100644 --- a/Components/ChatWindow.svelte +++ b/Components/ChatWindow.svelte @@ -40,6 +40,12 @@ let currentThought: string | null = null; + export function focusInput() { + tick().then(() => { + textareaElement?.focus(); + }); + } + onMount(() => { if (chatContainer) { plugin.registerDomEvent(chatContainer, 'click', handleLinkClick); @@ -76,6 +82,7 @@ } async function handleSubmit() { + focusInput(); if (!await semaphore.wait()) { return; } @@ -121,9 +128,6 @@ currentThought = null; isSubmitting = false; semaphore.release(); - tick().then(() => { - textareaElement?.focus(); - }); } } diff --git a/Components/TopBar.svelte b/Components/TopBar.svelte index 7b9f67f..038e431 100644 --- a/Components/TopBar.svelte +++ b/Components/TopBar.svelte @@ -9,6 +9,7 @@ import { openPluginSettings } from 'Helpers/Helpers'; export let leaf: WorkspaceLeaf; + export let onNewConversation: (() => void) | undefined = undefined; const plugin = Resolve(Services.AIAgentPlugin); const conversationService = Resolve(Services.ConversationFileSystemService); @@ -16,15 +17,18 @@ function startNewConversation() { conversationService.resetCurrentConversation(); conversationStore.reset(); + onNewConversation?.(); } async function deleteCurrentConversation() { await conversationService.deleteCurrentConversation(); conversationStore.reset(); + onNewConversation?.(); } function openConversationHistory() { const modal = Resolve(Services.ConversationHistoryModal); + modal.onModalClose = onNewConversation; modal.open(); } diff --git a/Modals/ConversationHistoryModal.ts b/Modals/ConversationHistoryModal.ts index 90f3809..5d8cf06 100644 --- a/Modals/ConversationHistoryModal.ts +++ b/Modals/ConversationHistoryModal.ts @@ -25,6 +25,7 @@ export class ConversationHistoryModal extends Modal { private component: Record | null = null; private items: ListItem[]; private conversations: Conversation[]; + public onModalClose?: () => void; constructor(app: App) { super(app); @@ -107,5 +108,7 @@ export class ConversationHistoryModal extends Modal { const { contentEl } = this; contentEl.empty(); + + this.onModalClose?.(); } } \ No newline at end of file diff --git a/Views/MainView.ts b/Views/MainView.ts index 7f521c0..89fc6fe 100644 --- a/Views/MainView.ts +++ b/Views/MainView.ts @@ -25,15 +25,16 @@ export class MainView extends ItemView { const container = this.contentEl; container.empty(); - // Mount TopBar + // Mount TopBar with reference to ChatWindow's focus function this.topBar = mount(TopBar, { target: container, props: { - leaf: this.leaf + leaf: this.leaf, + onNewConversation: () => this.input?.focusInput() } }); - // Mount ChatWindow + // Mount ChatWindow first this.input = mount(ChatWindow, { target: container, props: {}