Skip to content

Conversation

@alpalla
Copy link
Contributor

@alpalla alpalla commented Aug 28, 2025

Fixes #261387.

Transform to Camel Case

Single line transformations

I split this in two cases. When a single line (without line breaks) is selected, the behavior remains unchanged. I did this because I noticed unit tests that assert that white space characters should be considered as valid word boundaries.

Example

"camel from words" -> "camelFromWords"

Multiline transformations

On the other hand, in case of a selection spanning multiple lines I changed the relevant regex to only consider _ and - as valid word boundaries. Effectively guaranteeing correct transformations only when coming from kebab or snake case.

I did this because considering tabs as word boundaries will break the indentation for a code block. And as @RedCMD suggested, I also think it makes sense to treat a-b c-d as separate words (-> aB cD).

Transform to Pascal Case

Here I was much more conservative because this transformation has some extra logic to capitalize the first letter of a word

return words.map((word: string) => word.substring(0, 1).toLocaleUpperCase() + word.substring(1))
			.join('')

Therefore not using spaces and tabs as word boundaries would execute the above logic on spaces and tabs. It was easier to just address the line break problem here and not get lost in edge cases.

Testing

I added some unit tests, and this should be straightforward to test manually 🙌🏻

camelCaseTransformAction.mov

@RedCMD
Copy link
Contributor

RedCMD commented Aug 28, 2025

LGTM 🚀

cc @hediet

@hediet hediet enabled auto-merge (squash) September 8, 2025 14:26
@vs-code-engineering vs-code-engineering bot added this to the September 2025 milestone Sep 8, 2025
@hediet hediet merged commit c3500fa into microsoft:main Sep 8, 2025
17 checks passed
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Oct 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The Built-in "Transform to Camel Case" doen't handle line-breaks

5 participants