mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 13:25:11 +00:00
Toggle jump between Khoj side pane & previous editor via cmd, kbd shortcut
Improve quick navigation to, from Khoj side pane using Keyboard shortcut or Obsidian command
This commit is contained in:
@@ -2,7 +2,8 @@ import { Plugin, WorkspaceLeaf } from 'obsidian';
|
|||||||
import { KhojSetting, KhojSettingTab, DEFAULT_SETTINGS } from 'src/settings'
|
import { KhojSetting, KhojSettingTab, DEFAULT_SETTINGS } from 'src/settings'
|
||||||
import { KhojSearchModal } from 'src/search_modal'
|
import { KhojSearchModal } from 'src/search_modal'
|
||||||
import { KhojChatView } from 'src/chat_view'
|
import { KhojChatView } from 'src/chat_view'
|
||||||
import { updateContentIndex, canConnectToBackend, KhojView } from './utils';
|
import { updateContentIndex, canConnectToBackend, KhojView, jumpToPreviousView } from './utils';
|
||||||
|
import { KhojPaneView } from './pane_view';
|
||||||
|
|
||||||
|
|
||||||
export default class Khoj extends Plugin {
|
export default class Khoj extends Plugin {
|
||||||
@@ -89,15 +90,20 @@ export default class Khoj extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (leaf) {
|
if (leaf) {
|
||||||
|
const activeKhojLeaf = workspace.getActiveViewOfType(KhojPaneView)?.leaf;
|
||||||
|
// Jump to the previous view if the current view is Khoj Side Pane
|
||||||
|
if (activeKhojLeaf === leaf) jumpToPreviousView();
|
||||||
|
// Else Reveal the leaf in case it is in a collapsed sidebar
|
||||||
|
else {
|
||||||
|
workspace.revealLeaf(leaf);
|
||||||
|
|
||||||
if (viewType === KhojView.CHAT) {
|
if (viewType === KhojView.CHAT) {
|
||||||
// focus on the chat input when the chat view is opened
|
// focus on the chat input when the chat view is opened
|
||||||
let chatView = leaf.view as KhojChatView;
|
let chatView = leaf.view as KhojChatView;
|
||||||
let chatInput = <HTMLTextAreaElement>chatView.contentEl.getElementsByClassName("khoj-chat-input")[0];
|
let chatInput = <HTMLTextAreaElement>chatView.contentEl.getElementsByClassName("khoj-chat-input")[0];
|
||||||
if (chatInput) chatInput.focus();
|
if (chatInput) chatInput.focus();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// "Reveal" the leaf in case it is in a collapsed sidebar
|
|
||||||
workspace.revealLeaf(leaf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -333,6 +333,12 @@ export function createCopyParentText(message: string, originalButton: string = '
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function jumpToPreviousView() {
|
||||||
|
const editor: Editor = this.app.workspace.getActiveFileView()?.editor
|
||||||
|
if (!editor) return;
|
||||||
|
editor.focus();
|
||||||
|
}
|
||||||
|
|
||||||
export function pasteTextAtCursor(text: string | undefined) {
|
export function pasteTextAtCursor(text: string | undefined) {
|
||||||
// Get the current active file's editor
|
// Get the current active file's editor
|
||||||
const editor: Editor = this.app.workspace.getActiveFileView()?.editor
|
const editor: Editor = this.app.workspace.getActiveFileView()?.editor
|
||||||
|
|||||||
Reference in New Issue
Block a user