Skip to content

Improve Pair Matching Logic to Skip Parentheses Inside Strings #9344

Open
@Alan-MQ

Description

@Alan-MQ

Pair Matching Logic to Skip Parentheses Inside Strings

Issue Content

Description

In the current implementation of PairMatcher, the algorithm does not account for parentheses that may be located inside strings (e.g., "(')')"). This leads to incorrect jump behavior when users expect to skip parentheses within strings rather than treating them as matching pairs.

Steps to Reproduce

  1. In the editor, input a string such as: "(')')"
  2. Place the cursor on the first left parenthesis (.
  3. Use the % command to attempt to jump to the matching right parenthesis ).

Expected Behavior

The cursor should skip the right parenthesis inside the string and jump directly to the external matching right parenthesis.

Actual Behavior

The cursor incorrectly jumps to the right parenthesis inside the string.

Proposed Solution

I plan to add logic in the findPairedChar method to detect whether the current character is inside a string. Specifically, I will introduce a state variable to track whether we are inside a string and skip characters inside strings when processing parentheses. and make sure everything like ciw, ci" works fine

Related Code

  • findPairedChar method
  • PairMatcher class

Please feel free to let me know if you guys have any suggestions or thoughts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions