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

Improve Pair Matching Logic to Skip Parentheses Inside Strings #9344

Open
Alan-MQ opened this issue Nov 1, 2024 · 3 comments
Open

Improve Pair Matching Logic to Skip Parentheses Inside Strings #9344

Alan-MQ opened this issue Nov 1, 2024 · 3 comments

Comments

@Alan-MQ
Copy link

Alan-MQ commented Nov 1, 2024

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.

@Alan-MQ
Copy link
Author

Alan-MQ commented Nov 1, 2024

@J-Fields what's your take on this ? can I start working on this ?

@Alan-MQ
Copy link
Author

Alan-MQ commented Nov 1, 2024

nvim have the same problem , but I think maybe we should do better ?

@Ampersand-1
Copy link

Hello!

I created a PR regarding this issue (#9370). Please let me know if you have any feedback

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

No branches or pull requests

2 participants