Skip to content

fix: selection of string literals when string contains escape characters#295302

Merged
benvillalobos merged 5 commits intomicrosoft:mainfrom
RedCMD:fixStringSelectionEscapeChars
Feb 14, 2026
Merged

fix: selection of string literals when string contains escape characters#295302
benvillalobos merged 5 commits intomicrosoft:mainfrom
RedCMD:fixStringSelectionEscapeChars

Conversation

@RedCMD
Copy link
Contributor

@RedCMD RedCMD commented Feb 14, 2026

fixes #292784

merges multiple string tokens together
because escape characters and quote characters (with certain themes on) were separate tokens

"hello\"world"

double click after first quote ", before h

before:
image

after:
image

cc @dmitrivMS

dmitrivMS
dmitrivMS previously approved these changes Feb 14, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes double-click string selection when a string literal is tokenized into multiple adjacent StandardTokenType.String tokens (e.g., around escapes / punctuation), so selecting at the quote boundary selects the full string content as expected (issue #292784).

Changes:

  • Expand _trySelectStringContent to treat consecutive adjacent String tokens as a single logical string span.
  • Add a regression test for selecting string content when escape sequences cause token splits.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/vs/editor/browser/view/viewController.ts Updates string-content selection logic to merge adjacent string tokens into one selection span.
src/vs/editor/test/browser/view/viewController.test.ts Adds a regression test covering escape-driven token splitting during string selection.
Comments suppressed due to low confidence (1)

src/vs/editor/test/browser/view/viewController.test.ts:321

  • The token layout comment says the String token spans [8..22), but the provided tokens are intentionally split at 14 and 16. Updating the comment to describe the split segments (or removing the combined-range annotation) would make the test easier to understand and maintain.
		// Token layout: [0..8) Other  [8..22) String("hello\"world")  [22..23) Other
		const controller = createViewControllerWithTokens(text, [
			{ startIndex: 0, type: StandardTokenType.Other },
			{ startIndex: 8, type: StandardTokenType.String },
			{ startIndex: 14, type: StandardTokenType.String },
			{ startIndex: 16, type: StandardTokenType.String },
			{ startIndex: 22, type: StandardTokenType.Other },

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@dmitrivMS
Copy link
Contributor

@RedCMD please address the comments.

RedCMD and others added 2 commits February 14, 2026 22:28
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@RedCMD
Copy link
Contributor Author

RedCMD commented Feb 14, 2026

@dmitrivMS done.
(btw I'm not at my PC atm)

@benvillalobos benvillalobos merged commit bd6b93b into microsoft:main Feb 14, 2026
17 checks passed
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.

[Bug] Wrong string selection in double quotes on double click

4 participants