Inserting literal "\{" via snippets

Hi! I am trying to insert the literal “\{” as a snippet (for LaTeX) but only the “{” ends up getting dispatched.

I adopted this, and tried to followed the code in dev tools, and it looks like it’s in the step below that that the slash disappears. In the argument template, the slash is escaped

but after the call to Snippet.parse, the escaped slashes disappear

If I remove the curly braces (or add a space between the slashes and the curly braces) though, the slashes are retained


I’m just wondering if this is intended and might I be missing something? I also tried increasing the number of slashes and escaping the curly braces but the output is the same

That was a bug—" \\\\{ " should work to create a sting with a backslash before a brace. Attached patch fixes this.

1 Like

That was fast! It works now, thanks!

Any idea when this will be released? I think this is also the culprit for this reported issue.

I’ve tagged a @codemirror/autocomplete 6.16.1 with this fix.

1 Like

Thanks for the quick action! I tested 6.16.1 but unfortunately it doesn’t fix the issue I’m having (potentially this is a completely separate issue that should be its own thread).

Using snippetCompletion with the following template:

 snippetCompletion('"description": "${✨ A message from %\\{whom\\}: ✨}"', completion)

When the snippet is applied, the inserted text is:

"description": "✨ A message from %{whom\: ✨}"

Note that I escaped the literal braces as described in the snippet docs, but seems it somehow doesn’t handle the closing brace case properly:

To include a literal { or } in your template, put a backslash in front of it. This will be removed and the brace will not be interpreted as indicating a placeholder.

The code didn’t anticipate escaped brackets inside snippet fields. Attached patch should improve that.

1 Like

Looks like that fixed it. Thanks for all the work on code mirror!