Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
HyperEpsilon opened this issue Jun 29, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@HyperEpsilon
Copy link

HyperEpsilon commented Jun 29, 2022

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

Obsidian_2022-06-28_18-24-17.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 HyperEpsilon added the bug Something isn't working label Jun 29, 2022
@diminutivesloop
Copy link

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

@billy-bg
Copy link

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

@billy-bg
Copy link

billy-bg commented Aug 5, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants