Fixed note creation

This commit is contained in:
Simon Cambier
2022-04-22 21:32:13 +02:00
parent d709ce086a
commit cfb74f30b5
2 changed files with 19 additions and 18 deletions

View File

@@ -24,3 +24,19 @@ export async function openNote(
to: { line: pos.line + 10, ch: 0 },
})
}
export async function createNote(name: string): Promise<void> {
try {
const file = await app.vault.create(name + '.md', '# ' + name + '\n')
await app.workspace.openLinkText(file.path, '')
const view = app.workspace.getActiveViewOfType(MarkdownView)
if (!view) {
throw new Error('OmniSearch - No active MarkdownView')
}
const pos = view.editor.offsetToPos(name.length + 5)
pos.ch = 0
}
catch (e) {
console.error(e)
}
}