Put cursor on chat input when focus on chat view in Obsidian

This should improve fluidity of keyboard interactions with Khoj on
Obsidian.

Open Khoj chat view via keybinding or command pallete and ask
question using only the keyboard, with no mouse clicks required
This commit is contained in:
Debanjum Singh Solanky 2024-06-26 18:10:43 +05:30
parent 093e276908
commit fbb95ca342
2 changed files with 21 additions and 4 deletions

View file

@ -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 = <HTMLTextAreaElement>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);
}
}
}

View file

@ -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 = <HTMLTextAreaElement>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);
}
}
}