Skip to content

Fix title/camelCase commands stripping leading indentation Fixes#50523

Merged
SomeoneToIgnore merged 4 commits intozed-industries:mainfrom
OmChillure:fix-commands-remove-indentation
Mar 12, 2026
Merged

Fix title/camelCase commands stripping leading indentation Fixes#50523
SomeoneToIgnore merged 4 commits intozed-industries:mainfrom
OmChillure:fix-commands-remove-indentation

Conversation

@OmChillure
Copy link
Copy Markdown
Contributor

@OmChillure OmChillure commented Mar 2, 2026

Fixes: #48945

Description:

The convert:to-title-case, convert:to-upper-camel-case, and convert:to-lower-camel-case editor commands were stripping leading whitespace from each line of a multi-line selection.

Root cause: The conversion functions split on whitespace using .split_whitespace() and then joined the resulting words, discarding any leading spaces/tabs before the first word on each line.

Fix: Each line now preserves its leading whitespace by capturing and re-prepending it before applying the case conversion.

Tests: Added test cases covering multi-line selections with indentation for all three commands.

Video :

bug1fix.webm

Release Notes:

  • Fixed trailing whitespace handling on text case changes

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 2, 2026
@SomeoneToIgnore SomeoneToIgnore self-assigned this Mar 12, 2026
Copy link
Copy Markdown
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

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

Nice catch, but the fix seems somewhat odd given it's the library that removes the whitespaces, should we fix the rest of the invocations?
There are 6 total in this file but only 3 are being fixed and tested here which seems odd — seems that all of them would benefit from a common method that fixes things via trim_start.

Should we also use trim_end for similar reasons?

@OmChillure
Copy link
Copy Markdown
Contributor Author

OmChillure commented Mar 12, 2026

Nice catch, but the fix seems somewhat odd given it's the library that removes the whitespaces, should we fix the rest of the invocations? There are 6 total in this file but only 3 are being fixed and tested here which seems odd — seems that all of them would benefit from a common method that fixes things via trim_start.

Should we also use trim_end for similar reasons?

Thanks for the review. I updated this PR to centralize the fix and broaden coverage:

  • Added a shared convert_text_case helper and switched all relevant to_case(...) conversions to use it.
  • Covered all 6 to_case-based commands in editor.rs (title, snake, kebab, upper camel, lower camel, sentence) instead of only 3.
  • Considered your trim_end question and updated the helper to preserve both leading and trailing whitespace per line, so only the inner text is transformed, this would cleaner nad would save us form further regressions.
  • Expanded tests accordingly, including assertions for trailing whitespace to help prevent regressions.

Video :
Screencast from 2026-03-13 00-06-14.webm

Copy link
Copy Markdown
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

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

Thank you!

@SomeoneToIgnore SomeoneToIgnore enabled auto-merge (squash) March 12, 2026 19:24
@SomeoneToIgnore SomeoneToIgnore merged commit 7a61562 into zed-industries:main Mar 12, 2026
28 checks passed
tommyming pushed a commit to tommyming/zed that referenced this pull request Mar 13, 2026
…-industries#50523)

Fixes: zed-industries#48945

Description:

The convert:to-title-case, convert:to-upper-camel-case, and
convert:to-lower-camel-case editor commands were stripping leading
whitespace from each line of a multi-line selection.

Root cause: The conversion functions split on whitespace using
.split_whitespace() and then joined the resulting words, discarding any
leading spaces/tabs before the first word on each line.

Fix: Each line now preserves its leading whitespace by capturing and
re-prepending it before applying the case conversion.

Tests: Added test cases covering multi-line selections with indentation
for all three commands.

Video : 


[bug1fix.webm](https://github.com/user-attachments/assets/f4d25c55-bc6d-44e6-a989-7d9b4bc59ac9)

Release Notes:

- Fixed trailing whitespace handling on text case changes
@zelenenka zelenenka added the guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions label Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Commands for title and camel case conversion erroneously remove indentation

3 participants