tp.file.cursor() doesn't work for my template when I use in on text selected in the middle of the line. It only works on text select at the start or end of it.
Plugin information (please complete the following information):
- OS: macos 13.1 on M1 Mac.
- Templater version: 1.16.0.
- Obsidian version: 1.1.16.
- Templater settings: Attached a zipped
data.jsonfile. data.json.zip
Describe the bug
I have this template: [[<%tp.file.cursor() %>|<% tp.file.selection() %>]] in a file Misc/Wikilink Template.md which is added to my template hotkeys and assigned a hotkey. Let's say I have text like this:
word 1 word2 word3 word4
If I select word2 or 3 and trigger the hotkey, it puts the cursor before the [[ when its supposed to be after it as specified in the template. It works properly on word1 and 4.
Can reproduce. Seems to only happen in live preview mode, source mode works just fine.
I prefer to just use live preview.
I also have this issue in live preview.
Can confirm have the same issue
I have this issue too.
If anyone is here because of an issue with the template you use to insert wikilinks, I use the following workaround:
<%*
const editor = app.workspace.activeLeaf.view.editor;
const selectionStart = editor.getCursor('from');
editor.replaceSelection(`[[|${editor.getSelection()}]]`);
editor.setCursor(selectionStart.line, selectionStart.ch+2)
%>