Templater icon indicating copy to clipboard operation
Templater copied to clipboard

tp.file.cursor() puts the cursor at the beginning of the line if there are greater than 65,536 (2^16) characters

Open HyperEpsilon opened this issue 2 years ago • 3 comments

Plugin information (please complete the following information):

  • OS: Windows 10
  • Templater version: 1.12.0
  • Obsidian version: 0.14.15
  • Templater settings: default settings

Describe the bug When there are more than 65,536 (2^16) characters in a file after tp.file.cursor() finishes it's replacement, the cursor is put to the start of the line rather than to the correct position.

If there are less than 2^16 characters after replacement, everything works fine.

Expected behavior The cursor should jump to the correct position on the line.

Screenshots

Pay attention to the character count in the bottom right

https://user-images.githubusercontent.com/6267244/176325914-460b67a8-7b70-4fdc-a284-235fe7e6c6e2.mp4

Additional context It is possible that this is an issue with the EditorPosition interface, which I believe implements position (or ch) as a TypeScript number

https://marcus.se.net/obsidian-plugin-docs/api/interfaces/EditorPosition https://github.com/marcusolsson/obsidian-plugin-docs/blob/main/obsidian.d.ts (line 871)

Edit: Here is the test file with the thousands of characters for your own testing
templater-cursor-example.md

HyperEpsilon avatar Jun 29 '22 00:06 HyperEpsilon

I'm seeing this as well. I have a daily log file that I just append to the beginning of and now when I apply the template for the daily log my cursor is positioned before rather than after the list marker.

## <% tp.date.now("YYYY/MM/DD dddd") %> 
-<% tp.file.cursor(1) %> 

diminutivesloop avatar Jul 14 '23 12:07 diminutivesloop

i am also having this issue. Wonder if anyone has a fix for this?

billy-bg avatar Jul 16 '23 03:07 billy-bg

Update for anyone else experiencing this issue. I have made a quick plugin fix that can be used in conjunction with Templater as a replacement for the template-cursor functionality. Download found on my github profile here.

billy-bg avatar Aug 05 '23 17:08 billy-bg