diff --git a/src/interface/obsidian/src/main.ts b/src/interface/obsidian/src/main.ts index d7178f78..e0e09c24 100644 --- a/src/interface/obsidian/src/main.ts +++ b/src/interface/obsidian/src/main.ts @@ -88,7 +88,16 @@ export default class Khoj extends Plugin { await leaf?.setViewState({ type: viewType, active: true }); } - // "Reveal" the leaf in case it is in a collapsed sidebar - if (leaf) workspace.revealLeaf(leaf); + if (leaf) { + if (viewType === KhojView.CHAT) { + // focus on the chat input when the chat view is opened + let chatView = leaf.view as KhojChatView; + let chatInput = chatView.contentEl.getElementsByClassName("khoj-chat-input")[0]; + if (chatInput) chatInput.focus(); + } + + // "Reveal" the leaf in case it is in a collapsed sidebar + workspace.revealLeaf(leaf); + } } } diff --git a/src/interface/obsidian/src/pane_view.ts b/src/interface/obsidian/src/pane_view.ts index 74afacab..64a167dd 100644 --- a/src/interface/obsidian/src/pane_view.ts +++ b/src/interface/obsidian/src/pane_view.ts @@ -47,7 +47,15 @@ export abstract class KhojPaneView extends ItemView { await leaf?.setViewState({ type: viewType, active: true }); } - // "Reveal" the leaf in case it is in a collapsed sidebar - if (leaf) workspace.revealLeaf(leaf); + if (leaf) { + if (viewType === KhojView.CHAT) { + // focus on the chat input when the chat view is opened + let chatInput = this.contentEl.getElementsByClassName("khoj-chat-input")[0]; + if (chatInput) chatInput.focus(); + } + + // "Reveal" the leaf in case it is in a collapsed sidebar + workspace.revealLeaf(leaf); + } } }