tecosaur / LaTeX-Utilities

An add-on to LaTeX Workshop that provides some features that go beyond the bare essentials
MIT License
474 stars 28 forks source link

Live Snippet Cursor stepts out of paranthesis #384

Open PlisJan opened 1 year ago

PlisJan commented 1 year ago

Bug Report

Disable all the other extensions except for LaTeX Workshop and LaTeX Utilities, and check that you still see this issue.

You still see this issue?: Yes

Describe the bug

Live Snippet skips out of paranthesis if using +

image

To Reproduce

Steps to reproduce the behaviour:

  1. Use math environment e.g. align or `equation´
  2. Type (a -> vscode automatically closes the bracket -> (a)
  3. insert a plus sign (a+)

Expected behaviour

The cursor should stay inside the paranthesis. image

Logs

Please paste the whole log messages here, not parts of ones. It is very important to identify problems. If you think the logs are unrelated, please say so.

LaTeX Workshop Output ``` No usefull logs exists ```
LaTeX Utilities Output ``` [13:45:51] Initializing LaTeX Utilities. [13:45:51] Live Snippets Loaded [13:45:51] Completion Watcher Initialised [13:45:51] LaTeX Utilities Started [13:45:52] LaTeX Utilities version: 0.4.10 [13:48:09] onDidChangeActiveTextEditor_tex_wordcounter [13:48:09] onDidChangeActiveTextEditor_tex_wordcounter [13:48:09] TexCount args: -merge,-brief [13:48:10] TeXCount output for word: 15+0+0 (0/0/3/1) File: 1.tex [13:48:10] TexCount args: -merge,-brief,-char [13:48:10] TeXCount output for char: 105+0+0 (0/0/3/1) File: 1.tex [13:52:51] onDidChangeTextDocument [13:52:52] onDidChangeTextDocument [13:52:56] onDidChangeTextDocument [13:52:56] onDidChangeTextDocument ```
Developer Tools Console ``` No usefull logs exists ```

Screenshots

If applicable, add screenshots to help explain your problem.

Desktop

Additional context

khkrishna18 commented 1 year ago

I am experiencing the same problem. How to solve this?

Physicsphobia commented 10 months ago

just add $$1,$$2,$$3,...,$$0 in your snippets file, which can help you put the cursor in the right place

gusss1234 commented 10 months ago

just add $$1,$$2,$$3,...,$$0 in your snippets file, which can help you put the cursor in the right place

@Physicsphobia How do you do that exactly? I am not sure I particularly understand, very new to this. I think I just need an example (better if there is a bit of explanation). Thanks!

PlisJan commented 10 months ago

@gusss1234 Hit Ctrl+Shift+P, select LateX Utilities: Edit Live Snippets file and in the file that opens replace these lines

    {
    "prefix": "([^ &\\\\\\+\\-=<>\\|!~@])([\\+\\-=<>])$",
    "body": "$1 $2",
    "mode": "maths",
    "priority": -1,
    "description": "whitespace before operators",
    "triggerWhenComplete": true
  },
  {
    "prefix": "([\\+\\-=<>])([^ &\\\\\\+\\-=<>\\|!~])$",
    "body": "$1 $2",
    "mode": "maths",
    "priority": -1,
    "description": "whitespace after operators",
    "triggerWhenComplete": true
  },

against

  {
    "prefix": "([^ &\\\\\\+\\-=<>\\|!~@])([\\+\\-=<>])$",
    "body": "$1 $2$$1",
    "mode": "maths",
    "priority": -1,
    "description": "whitespace before operators",
    "triggerWhenComplete": true
  },
  {
    "prefix": "([\\+\\-=<>])([^ &\\\\\\+\\-=<>\\|!~])$",
    "body": "$1 $2$$1",
    "mode": "maths",
    "priority": -1,
    "description": "whitespace after operators",
    "triggerWhenComplete": true
  },

Then it should work.

gusss1234 commented 10 months ago

@PlisJan Thanks! I think it fixed it, need to add it to everything else now since it's not the only affected by operators. This should definitely be fixed in the main codebase.

gusss1234 commented 10 months ago

Before that is done, I think this fixes all space problems. Beware, I deleted dot(a) and ddot(a) snippets. latexUtilsLiveSnippets_guss.json

grepgrok commented 5 months ago

Yeah, I was having this same problem. Without looking at the code, I'm betting it has to do with VSCode not being told where to place the cursor after executing the snippet (or maybe being told to put it in the wrong place). I notice that when I have a snippet with a trigger 2 characters long which expands into 10 characters, the cursor is placed 10 - 2 = 8 characters after the end of the expansion.

This definitely seems like a bug. As a temporary fix, using the guss provided above would work well. For a cleaner fix, it should probably address the issue directly.

jhanschoo commented 5 months ago

For another minimal example, in inline math delimiters \( \), keep typing inn with live reformat on and watch the cursor get misplaced.