<%*
// Get the current cursor location
const cursor = app.workspace.activeLeaf.view.editor.getCursor()
// Move the cursor to the start of the document
app.workspace.activeLeaf.view.editor.setCursor({line: 0, ch: 0})
// Fold/unfold the YAML
app.commands.executeCommandById('editor:toggle-fold')
// Move the cursor back to the original location
app.workspace.activeLeaf.view.editor.setCursor(cursor)
%>
If you’re creating the Javascript file for use in tp.user, it would this format:
function main() {
const cursor = app.workspace.activeLeaf.view.editor.getCursor()
app.workspace.activeLeaf.view.editor.setCursor({line: 0, ch: 0})
app.commands.executeCommandById('editor:toggle-fold')
app.workspace.activeLeaf.view.editor.setCursor(cursor)
return ''
}
module.exports = main
Agreed, I even think there should be a separate section in the UI for note metadata so it isn’t in the main note. It could in reality be at the header still, but the UI could stick it in the sidebar for a much cleaner appearance.
I had this issue and here’s how I solved it. The problem was that I created the .js file in Obsidian as an .md file, and then renamed the extension .js using the file explorer. That caused an issue, perhaps something to do with how the spaces/new-lines were garbled. When instead I pasted the code into a blank .js file, it worked fine.