Maintain line breaks in transform to Camel and Pascal case actions #263781
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
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-das 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
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