This commit is contained in:
Simon Cambier
2022-08-01 10:20:04 +02:00
parent d0d23e48b9
commit 970971138d

View File

@@ -96,10 +96,19 @@ export async function openNote(
export async function createNote(name: string): Promise<void> { export async function createNote(name: string): Promise<void> {
try { try {
const file = await app.vault.create( let pathPrefix = ''
`${app.vault.getConfig('newFileFolderPath')}/${name}.md`, 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, '') await app.workspace.openLinkText(file.path, '')
const view = app.workspace.getActiveViewOfType(MarkdownView) const view = app.workspace.getActiveViewOfType(MarkdownView)
if (!view) { if (!view) {
@@ -109,6 +118,7 @@ export async function createNote(name: string): Promise<void> {
pos.ch = 0 pos.ch = 0
} }
catch (e) { catch (e) {
(e as any).message = 'OmniSearch - Could not create note: ' + (e as any).message
console.error(e) console.error(e)
throw e throw e
} }