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(1) %>" is performed with a delay of one hotkey activation in Obsidian 1.5.2 tables #1268

Open
Alicecomma opened this issue Dec 14, 2023 · 4 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Alicecomma
Copy link

Plugin information (please complete the following information):

  • OS: Win11
  • Templater version: 2.0.0 (fresh install on new vault)
  • Obsidian version: 1.5.2 (new vault)
  • Templater settings: Template folder location: "Templates/"; Automatic jump to cursor: TRUE; Template: "subscript.md" with contents <sub><% tp.file.selection() %><% tp.file.cursor(1) %></sub>; Hotkeys set-up: "Templates/subscript.md"; Hotkey: "Ctrl+," (replaced open settings)

Describe the bug
When I press Ctrl+, (set-up of the hotkey for subscript.md) it converts SELE to <sub>SELE<% tp.file.cursor(1) %</sub> if the hotkey is run inside of a table created by typing A|B enter -|- and adding a row with the plus-sign, typing a inside the first cell.

  • If I use my hotkey again, the cursor is gone as well as the unperformed <% tp.file.cursor(1) %>
  • If I use the hotkey again twice, the whole table row disappears
  • If I use it thrice, the table row appears again followed by, outside of the table, </sub> and next line </sub><br> | |. It may or may not display the initial selection

If I create the table below the first table using A|B enter -|- then the table is not created, but pressing enter with cursor at start of A|B does create the table. If I add a in the first cell and press the hotkey, the template is inserted with <br/> at the end. If I press the hotkey outside of the table next, it creates two cursors.

Expected behavior
Outside tables the hotkey works as expected, removing the tp command and teleporting the cursor. Inside tables, all kinds of unexpected things happen. Perhaps the Templater code is run after the table trying to repair itself with |? I don't understand what is happening but I'd expect the table cell to act as the hotkey does outside the table.

Screenshots
image

@Alicecomma Alicecomma added the bug Something isn't working label Dec 14, 2023
@Zachatoo
Copy link
Collaborator

Can reproduce, thanks for the report!

@Zachatoo
Copy link
Collaborator

It seems that <% tp.file.cursor() %> doesn't work in tables at all with the table update. I can manually type in a cursor and run the Jump to next cursor location command, and the template code will disappear but my cursor will not be in the table cell. If I try to type, nothing happens, my cursor is no longer in the editor.

I can add a line so the cursor executes, but it doesn't execute correctly, as explained above. Noting the change I made here.

async append_template_to_active_file(template_file: TFile): Promise<void> {
    // ...
    const editor = active_editor.editor;
    const doc = editor.getDoc();
    const oldSelections = doc.listSelections();
    doc.replaceSelection(output_content);
    await delay(1); // added this line so cursor jumper logic finds cursor to jump to
    // ...
}

@Zachatoo Zachatoo added the help wanted Extra attention is needed label Dec 27, 2023
@PeterBeckley
Copy link

PeterBeckley commented Dec 27, 2023

Also not working for me after updating Obsidian to 1.5.3 and Templater to 2.0.0. I have no tables to deal with, but have to trigger the jump manually. EDIT: Forgot to add that the cursor jump is triggered correctly when I have it as a step in a QuickAdd macro. I hope that helps and doesn't complicate troubleshooting.

@HyperEpsilon
Copy link

I'm also having this issue. I cannot jump out of tables using the cursor. It is quite annoying as my meeting template has several details recorded in table form.

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

No branches or pull requests

4 participants