pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

"Expand selection" can't select string without quotes in multiword strings

Open 750 opened this issue 7 months ago • 6 comments

For a string "cat dog", with cursor at a character withing cat, smartSelect should expand selection in the following order:

  1. cat
  2. cat dog
  3. "cat dog"

Instead step 2 is missing

Environment data

  • Pylance version: 2025.5.1
  • OS and version: macos 14.5 (23F79)
  • Python version (& distribution if applicable, e.g. Anaconda): 3.10

Code Snippet

some_string = "cat dog"

Repro Steps

  1. Place cursor at cat
  2. Expand selection. cat is now selected
  3. Expand selection again. Expected: cat dog is now selected. Actual: "cat dog" is now selected (with quotes!)

https://github.com/user-attachments/assets/6da79f00-9c4c-4684-9a81-96b766f2c6e3

750 avatar May 24 '25 11:05 750

Hi @750, I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.


Potentially Related Issues:

  • Expand Selection within quotes (known behavior; multiword strings select only the quoted block) #1878
  • “expand selection” behaves inconsistently (steps vary and skip inner text) #4393

The team will respond to your issue shortly. Please note this is a trial feature and may not be fully accurate. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or was incorrect, please give it a 👎. Your feedback helps us improve!

github-actions[bot] avatar May 24 '25 11:05 github-actions[bot]

I can see the related issues, however it is unclear whether this behaviour is a wontfix or just a forgotten minor bug.

750 avatar May 24 '25 11:05 750

The issues suggested by the AI assistant are actually unrelated. #1878 is from before we implemented smart select, and #4393 is a different issue that has since been fixed.

debonte avatar May 24 '25 16:05 debonte

@750, would you agree that this is an enhancement rather than a bug? I don't believe there are any guidelines from VS Code about exactly how languages should expand when performing smart select.

However, I can see that if you wanted to replace the entire string, selecting the contents (without the quotes) would be nice. The workaround (delete the quotes and readd them) seems simple though, so I don't think this is a high priority issue. It seems more like a nice to have.

If you disagree on the priority, please provide some more details on your use case and why selecting the string without quotes is important in your scenario.

debonte avatar May 24 '25 16:05 debonte

@debonte Lack of guidelines doesn't matter here because this is common sense imho. On the other hand you do not think this is a bug so maybe it is not really common sense after all.

btw default implementation of both JSON and Typescript behave the way I describe

Whether this is a bug or an enhancement is debatable but this of course is a minor issue

The workaround (delete the quotes and readd them) seems simple though

I do not think this is simple. This requires several other keystrokes, which can become a nuisance if done several times a day every day (which is how I summoned the courage to create this issue :-) )

If you disagree on the priority, please provide some more details on your use case and why selecting the string without quotes is important in your scenario.

Use case is that I have a string copied (i.e. from a webpage so no quotes) and want to replace a string variable value with that copy

750 avatar May 24 '25 17:05 750

btw default implementation of both JSON and Typescript behave the way I describe

Thanks for checking this. We do try to behave similarly to Typescript when possible, so that's a good motivation to address this.

debonte avatar May 24 '25 18:05 debonte

This issue has been fixed in prerelease version 2025.6.101, which we've just released. You can find the changelog here: CHANGELOG.md

rchiodo avatar Jul 03 '25 00:07 rchiodo

Beautiful, thank you

750 avatar Jul 03 '25 10:07 750