mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 23:48:56 +01:00
Add null checks, fix build errors in Khoj plugin on newer Obsidian
This commit is contained in:
parent
d8ace4d34c
commit
bbcdb8413d
4 changed files with 11 additions and 12 deletions
|
@ -243,13 +243,12 @@ export class KhojChatView extends KhojPaneView {
|
||||||
|
|
||||||
if (referenceFile) {
|
if (referenceFile) {
|
||||||
// Find vault file associated with current reference
|
// Find vault file associated with current reference
|
||||||
let linkToEntry = getLinkToEntry(mdFiles.concat(pdfFiles), referenceFile, reference);
|
const linkToEntry = getLinkToEntry(mdFiles.concat(pdfFiles), referenceFile, reference);
|
||||||
|
|
||||||
let linkElement: Element;
|
const linkElement: Element = referenceButton.createEl('span');
|
||||||
linkElement = referenceButton.createEl('span');
|
|
||||||
linkElement.setAttribute('title', escaped_ref);
|
linkElement.setAttribute('title', escaped_ref);
|
||||||
linkElement.textContent = referenceFile;
|
linkElement.textContent = referenceFile;
|
||||||
if (linkToEntry && linkToEntry) {
|
if (linkElement && linkToEntry) {
|
||||||
linkElement.classList.add("reference-link");
|
linkElement.classList.add("reference-link");
|
||||||
linkElement.addEventListener('click', (event) => {
|
linkElement.addEventListener('click', (event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
@ -293,6 +292,7 @@ export class KhojChatView extends KhojPaneView {
|
||||||
// Render markdow to HTML DOM element
|
// Render markdow to HTML DOM element
|
||||||
let chat_message_body_text_el = this.contentEl.createDiv();
|
let chat_message_body_text_el = this.contentEl.createDiv();
|
||||||
chat_message_body_text_el.className = "chat-message-text-response";
|
chat_message_body_text_el.className = "chat-message-text-response";
|
||||||
|
// @ts-ignore
|
||||||
MarkdownRenderer.renderMarkdown(message, chat_message_body_text_el, '', null);
|
MarkdownRenderer.renderMarkdown(message, chat_message_body_text_el, '', null);
|
||||||
|
|
||||||
// Replace placeholders with LaTeX delimiters
|
// Replace placeholders with LaTeX delimiters
|
||||||
|
|
|
@ -85,10 +85,10 @@ export default class Khoj extends Plugin {
|
||||||
// Our view could not be found in the workspace, create a new leaf
|
// Our view could not be found in the workspace, create a new leaf
|
||||||
// in the right sidebar for it
|
// in the right sidebar for it
|
||||||
leaf = workspace.getRightLeaf(false);
|
leaf = workspace.getRightLeaf(false);
|
||||||
await leaf.setViewState({ type: viewType, active: true });
|
await leaf?.setViewState({ type: viewType, active: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// "Reveal" the leaf in case it is in a collapsed sidebar
|
// "Reveal" the leaf in case it is in a collapsed sidebar
|
||||||
workspace.revealLeaf(leaf);
|
if (leaf) workspace.revealLeaf(leaf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,10 +44,10 @@ export abstract class KhojPaneView extends ItemView {
|
||||||
// Our view could not be found in the workspace, create a new leaf
|
// Our view could not be found in the workspace, create a new leaf
|
||||||
// in the right sidebar for it
|
// in the right sidebar for it
|
||||||
leaf = workspace.getRightLeaf(false);
|
leaf = workspace.getRightLeaf(false);
|
||||||
await leaf.setViewState({ type: viewType, active: true });
|
await leaf?.setViewState({ type: viewType, active: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// "Reveal" the leaf in case it is in a collapsed sidebar
|
// "Reveal" the leaf in case it is in a collapsed sidebar
|
||||||
workspace.revealLeaf(leaf);
|
if (leaf) workspace.revealLeaf(leaf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,10 +139,9 @@ export async function updateContentIndex(vault: Vault, setting: KhojSetting, las
|
||||||
export async function createNote(name: string, newLeaf = false): Promise<void> {
|
export async function createNote(name: string, newLeaf = false): Promise<void> {
|
||||||
try {
|
try {
|
||||||
let pathPrefix: string
|
let pathPrefix: string
|
||||||
// @ts-ignore
|
switch (this.app.vault.getConfig('newFileLocation')) {
|
||||||
switch (app.vault.getConfig('newFileLocation')) {
|
|
||||||
case 'current':
|
case 'current':
|
||||||
pathPrefix = (app.workspace.getActiveFile()?.parent.path ?? '') + '/'
|
pathPrefix = (this.app.workspace.getActiveFile()?.parent.path ?? '') + '/'
|
||||||
break
|
break
|
||||||
case 'folder':
|
case 'folder':
|
||||||
pathPrefix = this.app.vault.getConfig('newFileFolderPath') + '/'
|
pathPrefix = this.app.vault.getConfig('newFileFolderPath') + '/'
|
||||||
|
@ -151,7 +150,7 @@ export async function createNote(name: string, newLeaf = false): Promise<void> {
|
||||||
pathPrefix = ''
|
pathPrefix = ''
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
await app.workspace.openLinkText(`${pathPrefix}${name}.md`, '', newLeaf)
|
await this.app.workspace.openLinkText(`${pathPrefix}${name}.md`, '', newLeaf)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Khoj: Could not create note.\n' + (e as any).message);
|
console.error('Khoj: Could not create note.\n' + (e as any).message);
|
||||||
throw e
|
throw e
|
||||||
|
|
Loading…
Reference in a new issue