Templater icon indicating copy to clipboard operation
Templater copied to clipboard

New note replaces File Explorer panel when using Create new note from template

Open codyburleson opened this issue 1 year ago • 10 comments

This never happened before, but now, in the new version of Obsidian, when I choose to create a new note from template, the new note is created right there in place of the File Explorer tab. I have to close and reopen Obsidian in order to get the file explorer tab back. This is Obsidian version 0.15.6 running on Windows 10.

codyburleson avatar Jul 16 '22 22:07 codyburleson

Super annoying bug, I think I will try to roll back to the previous version of Obsidian till this gets worked out.

akay64 avatar Jul 17 '22 14:07 akay64

Hey Cody! Nice to see ya after a while. I think you're capable of fixing this actually. app.workspace.activeLeaf behavior changed with 15.4 and we need to handle it a little differently. You can find an example in my PR for obsidian-spaced-repetition. In case you can't get to it, I'll try and push a fix in a few days.

AB1908 avatar Jul 17 '22 14:07 AB1908

Similar to (#670). I currently use this workaround by adding it to my templates.

<%*
if (this.app.workspace.activeLeaf.getViewState()?.type =="file-explorer") {
this.app.workspace.setActiveLeaf(this.app.workspace.getMostRecentLeaf())
}
%>

Or open command palette and run Reload app without saving to get your File Manager back.

welpdx avatar Jul 18 '22 01:07 welpdx

@AB1908 is this the PR you were talking about? https://github.com/st3v3nmw/obsidian-spaced-repetition/pull/469 Pretty comprehensive

welpdx avatar Jul 18 '22 01:07 welpdx

Yep, that's the one.

AB1908 avatar Jul 18 '22 04:07 AB1908

I guess I'll get around to working on this but no guarantees on the timeframe.

AB1908 avatar Jul 25 '22 11:07 AB1908

#670 #671 #691 fixing this issue would address all 3 posts. Are you gonna make a pr? XD

welpdx avatar Jul 25 '22 18:07 welpdx

Haha so many contributions, hard to stay on top of it all.

AB1908 avatar Jul 25 '22 19:07 AB1908

I also have this issue on arch linux. Obsidian version: v0.15.6.

yummy527 avatar Jul 27 '22 01:07 yummy527

I have this problem as well on 0.15.9 Another work around is to right click on the tab of the new note and click "Reveal file in navigation"

DR3AIVI avatar Aug 11 '22 02:08 DR3AIVI

I am able to fox this by changing the const active_leaf = line in the if(open_new_note) block in Templater.ts. See BEFORE commented out and AFTER as the line just after...

if (open_new_note) {
            // const active_leaf = this.app.workspace.activeLeaf;
            const active_leaf = yield this.app.workspace.getLeaf(false);
            if (!active_leaf) {
                log_error(new TemplaterError("No active leaf"));
                return;
            }

For those who want this fix before it can be made in a PR, just navigate into your vault > .obsidian > plugins > templater-obsidian > main.js, search the text, and make the change there. Save the file, then restart Obsidian.

Instead of getting the activeLeaf from the workspace, which is the File Explorer when you're right-clicking to create a new file from a template, this gets the active leaf from the root split, which is more commonly where you want to be editing.

If a few people could try this and make sure it gets you what you expect, then I could open a PR if someone else doesn't beat me to it.

codyburleson avatar Aug 19 '22 03:08 codyburleson

@codyburleson Thanks. It works on my machine running arch linux. By the way, have been waiting for update for one or two month.

yummy527 avatar Aug 24 '22 06:08 yummy527

@codyburleson thanks you’re a life saver, I like your name too.

craldaz avatar Aug 25 '22 17:08 craldaz

I've submitted the following pull request for this issue: https://github.com/SilentVoid13/Templater/pull/736

codyburleson avatar Aug 27 '22 16:08 codyburleson

Closing as fixed with pull request merge #736; validated with plugin update from marketplace/

codyburleson avatar Sep 02 '22 18:09 codyburleson