Templater icon indicating copy to clipboard operation
Templater copied to clipboard

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.

Open YousufSSyed opened this issue 2 years ago • 6 comments

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.json file. 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.

YousufSSyed avatar Apr 17 '23 22:04 YousufSSyed

Can reproduce. Seems to only happen in live preview mode, source mode works just fine.

Zachatoo avatar Apr 18 '23 01:04 Zachatoo

I prefer to just use live preview.

YousufSSyed avatar Apr 18 '23 01:04 YousufSSyed

I also have this issue in live preview.

MoltenMonster avatar May 12 '23 02:05 MoltenMonster

Can confirm have the same issue

jjqpot avatar Jun 17 '23 04:06 jjqpot

I have this issue too.

tprotopopescu avatar Sep 30 '23 13:09 tprotopopescu

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)
%>

anormananderson avatar Jul 18 '24 18:07 anormananderson