From 970971138d9b06e927499326c62657210911ba7b Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Mon, 1 Aug 2022 10:20:04 +0200 Subject: [PATCH] Fixed #88 --- src/notes.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/notes.ts b/src/notes.ts index 4d56e08..5a8f648 100644 --- a/src/notes.ts +++ b/src/notes.ts @@ -96,10 +96,19 @@ export async function openNote( export async function createNote(name: string): Promise { try { - const file = await app.vault.create( - `${app.vault.getConfig('newFileFolderPath')}/${name}.md`, - '', - ) + let pathPrefix = '' + switch (app.vault.getConfig('newFileLocation')) { + case 'current': + pathPrefix = (app.workspace.getActiveFile()?.parent.path ?? '') + '/' + break + case 'folder': + pathPrefix = app.vault.getConfig('newFileFolderPath') + '/' + break + default: // 'root' + pathPrefix = '' + break + } + const file = await app.vault.create(`${pathPrefix}${name}.md`, '') await app.workspace.openLinkText(file.path, '') const view = app.workspace.getActiveViewOfType(MarkdownView) if (!view) { @@ -109,6 +118,7 @@ export async function createNote(name: string): Promise { pos.ch = 0 } catch (e) { + (e as any).message = 'OmniSearch - Could not create note: ' + (e as any).message console.error(e) throw e }