artisticat1 / obsidian-latex-suite

Make typesetting LaTeX as fast as handwriting through snippets, text expansion, and editor enhancements
MIT License
1.28k stars 52 forks source link

[BUG] When using the "\n" newline character as a trigger, it will not trigger a response. #295

Closed Atomesh closed 4 months ago

Atomesh commented 4 months ago

Description

I hope that when a newline occurs, when the "Enter" key is pressed, it will trigger a function to modify the text, such as automatically adding the time as a block ID. I tried searching for keywords like "newline" and "\n" in the issue, and looked for examples, but I found nothing.

To Reproduce

I have used the following configuration: {trigger: "\n", replacement: () => {/* some custom function */}, options: "tA",}

Expected Behavior

I hope the function is triggered.

Additional Info

If there are any other solutions, please let me know. What I expect is an automatic trigger every time I press Enter, without any additional actions.

Atomesh commented 4 months ago

I found the reason, if key not text character, it will not be trigger. In run_snippets.ts line 45

        if (snippet.options.automatic || snippet.type === "visual") {
            // If the key pressed wasn't a text character, continue
            if (!(key.length === 1)) continue;

            effectiveLine += key;
        }

For those who need it, you can comment out this section in the source code to enable triggering actions with keys like Enter and Backspace, fulfilling specific requirements. Note that in the trigger, 'Enter' should be used as the trigger value instead of '\n', as this could lead to many unexpected behaviors,like cursor position. This method should only be used as a hack.

I suspect the reason for the misplaced position lies within the computeTabstops method, but I'm struggling to comprehend this code snippet.

A feasible improvement could be to introduce a new mode specifically for handling non-text characters' input to avoid conflicts. However, since this would be a feature request, I'll go ahead and close this issue.

If there are any plugins or methods for overriding input, please kindly let me know. I would be extremely grateful.