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

fix: avoid escaping the exact word search twice #8566

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Tal500
Copy link

@Tal500 Tal500 commented Sep 8, 2023

Apparently, on exact word search, the word is getting regexp-escaped twice - once in

if (isExact) {
currentWord = _.escapeRegExp(currentWord);
}
and again in
const escapedNeedle = escapeRegExp(needle).replace('/', '\\/');
const searchString = isExact ? `\\<${escapedNeedle}\\>` : escapedNeedle;
, so this PR just drop the former.

The impact for the user happens when the user configures for VSCode "what is a word". For example, my VSCode configuration on the R language is:

"[r]": {
    // This makes sure that the "." character doesn't separate symbol.
    "editor.wordSeparators": "`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?",
}

It's hard to notice, but the difference is that . isn't appear there, but appear in the following. The default value for this option is:

"editor.wordSeparators": "`~!@#$%^&*()-=+[{]}\\|;:'\",.<>/?"

I do like that VSCodeVim treat my word correctly according to VSCode prefs, but I think that VSCodeVim should treat this word correctly on search (probably it was just a mistake in the code).

Copy link
Member

@J-Fields J-Fields left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please write a test that fails before this change and passes after?

@Tal500
Copy link
Author

Tal500 commented Oct 24, 2023

Could you please write a test that fails before this change and passes after?

Added tests

@Tal500 Tal500 requested a review from J-Fields October 24, 2023 17:21
@J-Fields
Copy link
Member

Thanks! But these tests seem to succeed before your change as well - mind adding one that tests the change? You can adjust the config for a test by passing config to newTest.

@Tal500
Copy link
Author

Tal500 commented Oct 25, 2023

Thanks! But these tests seem to succeed before your change as well - mind adding one that tests the change? You can adjust the config for a test by passing config to newTest.

I was debating how to do this so. The problem with the "config" parameter is that it doesn't allow me to change the non-vim-specific-extension configuration of VSCode. Here, what I need is to modify the global VScide config editor.wordSeparators, how to then?

@J-Fields
Copy link
Member

Ah, right, I should really add a way to do that easily. For now just put vscode.workspace.getConfiguration(...).update(...) in setup and reverse it in teardown.

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

Successfully merging this pull request may close these issues.

2 participants