Skip to content

Cursor Position Jumps Incorrectly When Using Snippets in Inline Math Mode \( \) #406

@huang706

Description

@huang706

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

When using snippets to automatically add spaces around operators (like =) in my document, the cursor position incorrectly jumps when I'm inside inline math environments \(...\). Specifically, after typing an operator like =, the cursor jumps backward to a position right after the opening \ character, resulting in corrupted LaTeX formulas.

To Reproduce

Steps to reproduce the behavior:

  1. Create a LaTeX document with the following snippets in your settings:
{
    "prefix": "([^ &\\\\\\+\\-=<>\\|!~@])([\\+\\-=<>])$",
    "body": "$1 $2",
    "mode": "maths",
    "priority": -1,
    "triggerWhenComplete": true
},
{
    "prefix": "([\\+\\-=<>])([^ &\\\\\\+\\-=<>\\|!~])$",
    "body": "$1 $2",
    "mode": "maths",
    "priority": -1,
    "triggerWhenComplete": true
}
  1. Start typing an inline math formula: \(y=x\)
  2. After typing the = character, observe the cursor position

Expected behaviour

Expected: The cursor should remain at the correct position after the = sign, and the snippet should add a space after the = sign, resulting in \(y=\x).

Actual behavior

Actual: The cursor incorrectly jumps to a position after the opening \ character, and the snippet adds the space in the wrong location, resulting in something like \(y =\x) when continuing to type.

By the way, the set {} turns out to be the same condition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions