SilentVoid13 / Templater

A template plugin for obsidian
https://silentvoid13.github.io/Templater
GNU Affero General Public License v3.0
3.16k stars 190 forks source link

tp.file.cursor() does not work #583

Closed qawatake closed 2 years ago

qawatake commented 2 years ago

Plugin informations (please complete the following information):

Describe the bug I create a zettelkasten note by the core zettelkasten plugin with the following template:

# <% tp.file.cursor() %>

After creating a note, the cursor is on the file name field.

Expected behavior After creating a zettelkasten note, the cursor should be inserted after #.

Screenshots Image from Gyazo

Additional context Updating the version caused this bug. Version 1.9.x did not have this bug.

liamcain commented 2 years ago

This looks like the expected behavior to me. The zettlekasten prefixer plugin allows you to also provide a descriptive name for your file. So the filename field should stay focused to allow you to add your note title (e.g. 202203130901 my note). When you press Enter your cursor will be at the location of tp.file.cursor().

qawatake commented 2 years ago

@liamcain

Thank you for your reply! I see. I have checked the changelog and found https://github.com/SilentVoid13/Templater/blob/master/CHANGELOG.md#bug-fixes.

By the way, is it possible to make these options selectable? I would like to have the cursor immediately go to the text, as it was originally supposed to do.

liamcain commented 2 years ago

I don't think that behavior was ever the intention of the cursor jump, so I'd rather not add it back even as an option. In my opinion, it was only a bug. However, if you've gotten used to the behavior and would like to recreate it, I recommend adding the following to the top of your template:

<%* app.workspace.activeLeaf.view.editor.focus() -%>

That will immediately cause the file to get focused on creation, which will be the same behavior you were seeing with the cursor jump previously.

qawatake commented 2 years ago

All right, I will try to get used to the new behavior. (By the way, using the workaround you gave me, the cursor does not seem to be at the exact position I specified.)

liamcain commented 2 years ago

(By the way, using the workaround you gave me, the cursor does not seem to be at the exact position I specified.)

Strange, I tested with this template and it worked as expected for me.

<%* app.workspace.activeLeaf.view.editor.focus() -%>
aasdfasdftesting

# <% tp.file.cursor() %>

---

testing, cursor should be above this
qawatake commented 2 years ago

@liamcain

Sorry, I made a mistake. Your code works perfectly! Thank you very much!