Unfold when templater command runs
See original GitHub issueI’m using a templater command that replace - [x]
with - [ ]
, here is the code
<%*
const text = tp.file.content
const output = text.replaceAll('- [x]','- [ ]')
const file = tp.file.find_tfile(tp.file.title)
await app.vault.modify(file, output)
_%>
And when I execute this command, (because the text being replaced is underneath a folded heading with a crease) it automatically unfolds the heading.
Is the plugin supposed to behave this way ? Is there a way to make it stay folded even when executing the templater command ?
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
15 Easy Templater Commands For Obsidian - Red Gregory
Navigate to command palette (command + P). Find Templater : Open Insert Template modal. All files inside the template folder will be found...
Read more >Automation of AddNewTransfer - from a folded to unfolded ...
I've got a script (below) which uses the AddNewTransfer method, but gives a null result, by which I mean that the command runs,...
Read more >Using the Obsidian Templater Plugin - YouTube
What IS the Obsidian Templater plugin and more importantly, how do you use it? I outline the three main use cases for it,...
Read more >Trial templates & tables - PennController for IBEX
Multi-trial experiments using templates ... the experiment runs (for more on how the group value is chosen on a given run of the...
Read more >SilentVoid13/Templater: A template plugin for obsidian - GitHub
Only run code / commands that you understand, from trusted sources. Template Showcase / Questions / Ideas / Help. Go to the discussion...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So it’s ugly but you can do this:
Hi @imeed166, this behavior is expected because your template is using
vault.modify
. Themodify
function is “dumb” in that it replaces all the contents with a file with new contents. So Obsidian doesn’t know anything about the nature of the changes. It can’t tell that most of the content is the same and that just the checkboxes are unchecked. So the expected behavior is that all your fold information is cleared out. This behavior will happen with or without this plugin.The simplest fix for now is to include the following at the end of your template:
app.commands.executeCommandById('creases:fold');
That will refold your creases after unchecking the checkboxes.
A better fix would involve using CodeMirror to actually just modify the lines with the checkboxes. But I think this behavior is likely too complex for a simple template.