Skip to content

git_ui: Count commit title length by characters instead of bytes#57025

Merged
MrSubidubi merged 1 commit into
zed-industries:mainfrom
koxya:fix/commit-title-length-multibytes
May 18, 2026
Merged

git_ui: Count commit title length by characters instead of bytes#57025
MrSubidubi merged 1 commit into
zed-industries:mainfrom
koxya:fix/commit-title-length-multibytes

Conversation

@koxya

@koxya koxya commented May 18, 2026

Copy link
Copy Markdown
Contributor

What

  • Replace title.len() with title.chars().count() in the commit title length check, so the limit is measured in Unicode characters instead of UTF-8 bytes.
  • Applied in two places that share the same logic:
    • crates/git_ui/src/git_panel.rs — Git panel's inline warning
    • crates/git_ui/src/commit_modal.rs — commit modal's inline warning

Why

The commit title length check used str::len(), which returns UTF-8 byte length rather than character count. As a result, titles containing multi-byte characters (Japanese, Chinese, emoji, etc.) triggered the warning far below the configured commit_title_max_length — around 24 characters instead of the default 72.

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability

  • Unsafe blocks (if any) have justifying comments

  • The content is consistent with the UI/UX checklist

    • Before

      Screen.Recording.2026-05-18.at.10.39.24.mov
    • After

      Screen.Recording.2026-05-18.at.10.42.07.mov
  • Tests cover the new/changed behavior

  • Performance impact has been considered and is acceptable

Closes #ISSUE

Release Notes:

  • Fixed commit title length check miscounting multi-byte characters as multiple characters.

Switch to `chars().count()` so the multi-byte character handling matches what users perceive as "characters".
Extract a shared `commit_title_exceeds_limit` helper used by both the git panel and commit modal, and add unit tests.

Release Notes:

- Fixed commit title length warning miscounting multi-byte characters in the Git panel and commit modal.
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label May 18, 2026
@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label May 18, 2026
@koxya koxya marked this pull request as ready for review May 18, 2026 04:48
@koxya koxya changed the title git_ui: Count commit title length by characters instead of bytes fix: Count commit title length by characters instead of bytes May 18, 2026
@maxdeviant maxdeviant changed the title fix: Count commit title length by characters instead of bytes git_ui: Count commit title length by characters instead of bytes May 18, 2026

@MrSubidubi MrSubidubi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

NIce find and fix, even better given that you added a test for this. Thank you and congratulations to your first contribution! 🎉

@MrSubidubi MrSubidubi added this pull request to the merge queue May 18, 2026
Merged via the queue into zed-industries:main with commit 8ce894b May 18, 2026
47 checks passed
TomPlanche pushed a commit to TomPlanche/zed that referenced this pull request May 20, 2026
…-industries#57025)

# What

- Replace `title.len()` with `title.chars().count()` in the commit title
length check, so the limit is measured in Unicode characters instead of
UTF-8 bytes.
- Applied in two places that share the same logic:
  - `crates/git_ui/src/git_panel.rs` — Git panel's inline warning
  - `crates/git_ui/src/commit_modal.rs` — commit modal's inline warning

# Why

The commit title length check used str::len(), which returns UTF-8 byte
length rather than character count. As a result, titles containing
multi-byte characters (Japanese, Chinese, emoji, etc.) triggered the
warning far below the configured commit_title_max_length — around 24
characters instead of the default 72.


Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
  - Before


https://github.com/user-attachments/assets/a895530c-2f73-470c-97fa-29d9467c14e1

  - After


https://github.com/user-attachments/assets/ffbe1ba2-0ccc-4b02-87f5-836da7841dd9


- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes #ISSUE

Release Notes:

- Fixed commit title length check miscounting multi-byte characters as
multiple characters.
TomPlanche pushed a commit to TomPlanche/zed that referenced this pull request Jun 2, 2026
…-industries#57025)

# What

- Replace `title.len()` with `title.chars().count()` in the commit title
length check, so the limit is measured in Unicode characters instead of
UTF-8 bytes.
- Applied in two places that share the same logic:
  - `crates/git_ui/src/git_panel.rs` — Git panel's inline warning
  - `crates/git_ui/src/commit_modal.rs` — commit modal's inline warning

# Why

The commit title length check used str::len(), which returns UTF-8 byte
length rather than character count. As a result, titles containing
multi-byte characters (Japanese, Chinese, emoji, etc.) triggered the
warning far below the configured commit_title_max_length — around 24
characters instead of the default 72.


Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
  - Before


https://github.com/user-attachments/assets/a895530c-2f73-470c-97fa-29d9467c14e1

  - After


https://github.com/user-attachments/assets/ffbe1ba2-0ccc-4b02-87f5-836da7841dd9


- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes #ISSUE

Release Notes:

- Fixed commit title length check miscounting multi-byte characters as
multiple characters.
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 first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants