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

[FEATURE] Prevent double backslashes when replacing a snippet #201

Open
RyotaUshio opened this issue Sep 27, 2023 · 3 comments
Open

[FEATURE] Prevent double backslashes when replacing a snippet #201

RyotaUshio opened this issue Sep 27, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@RyotaUshio
Copy link
Contributor

RyotaUshio commented Sep 27, 2023

Hi, thank you so much for this great plugin!

Description of the Problem

Let's take {trigger: "sum", replacement: "\\sum", options: "mA"} as an example.

For me, it's difficult to be consistent enough to refrain from typing \sum instead of just sum.
Most of the time I type just sum, but sometimes I carelessly type \sum, which results in double backslashes, i.e. \\sum.

Description of the Solution

It would be great if this plugin had the option to disable replacement when there is already a backslash so that the result will be \sum regardless of whether I typed the backslash or not.

Additional

I could partially resolve this problem by replacing the snippet with {trigger: "[^\\\\]sum", replacement: "\\sum", options: "rmA"} but it inserts \sum at an unexpected position:

Screen.Recording.2023-09-27.at.18.42.19.mov
@RyotaUshio RyotaUshio added the enhancement New feature or request label Sep 27, 2023
@RyotaUshio
Copy link
Contributor Author

RyotaUshio commented Sep 27, 2023

As for the last point, {trigger: "([^\\\\])sum", replacement: "[[0]]\\sum", options: "rmA"} solved the issue.
But doing this for all snippets will be hard work, given the variety of the snippets (such as tabstops).
For example, the same problem applies to {trigger: "int", replacement: "\\int $0 \\, d${1:x} $2", options: "mA"} as well.

@artisticat1
Copy link
Owner

Hi! Glad you're enjoying the plugin. This can be considered for a future release.

How should the plugin handle a snippet like {trigger: "sum", replacement: "\\sum_{${0:i}=${1:1}}^{${2:N}}", options: "mA"} when \sum is typed?

@RyotaUshio
Copy link
Contributor Author

Thank you for the quick response!

That's a good example... I said a snippet should be disabled for \sum, but now I've realized it's not perfect.
So let me correct myself: if double backslashes \\ are detected at the starting position of the result after trigger is replaced by replacement, then they should be replaced with a single backslash \.

In other words, sum and \sum should give the same result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants