Skip to content

tab_switcher: Middle-truncate long picker filenames - #59072

Merged
ChristopherBiscardi merged 1 commit into
zed-industries:mainfrom
saberoueslati:tab-bar-middle-truncation
Jun 11, 2026
Merged

tab_switcher: Middle-truncate long picker filenames#59072
ChristopherBiscardi merged 1 commit into
zed-industries:mainfrom
saberoueslati:tab-bar-middle-truncation

Conversation

@saberoueslati

Copy link
Copy Markdown
Contributor

Context

This follow-up was inspired by Christopher’s suggestion in the review comment on #58483: long filenames should truncate in the middle so both the beginning and the suffix/extension remain visible.

Previously, very long filenames in picker rows could still be clipped or end-truncated, making files with shared prefixes hard to distinguish. This adds middle-truncation support to GPUI text overflow and applies it to filename-focused picker surfaces: the tab switcher and the Ctrl-P file finder. Normal editor tab bar behavior remains unchanged and continues to use the existing title length cap.

How to Review

  • crates/gpui/src/style.rs, crates/gpui/src/styled.rs, crates/gpui/src/elements/text.rs, crates/gpui/src/text_system/line_wrapper.rs: Adds TextOverflow::TruncateMiddle, wires it through text layout, and implements middle truncation while preserving valid text runs. Very narrow widths now show the truncation affix instead of falling back to the abruptly clipped original text.

  • crates/ui/src/components/label/label_like.rs, crates/ui/src/components/label/label.rs, crates/ui/src/components/label/highlighted_label.rs: Exposes middle truncation through the shared label components.

  • crates/workspace/src/item.rs, crates/editor/src/items.rs, crates/workspace/src/pane.rs, crates/tab_switcher/src/tab_switcher.rs: Adds an explicit tab-content opt-in for middle truncation. The tab switcher enables it, while the normal tab bar and dragged tabs keep their existing behavior.

  • crates/file_finder/src/file_finder.rs: Applies middle truncation to Ctrl-P file finder filenames and lets the path shrink from the start so long paths do not hide important filename suffixes.

Manual test before change :

Screencast.from.2026-06-10.22-59-28.webm

Manual test after change :

Screencast.from.2026-06-10.22-54-48.webm

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
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Improved long filename truncation in the tab switcher and file finder so extensions remain visible.

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jun 10, 2026
@ChristopherBiscardi ChristopherBiscardi self-assigned this Jun 11, 2026
@ChristopherBiscardi ChristopherBiscardi added the area:ui/tabs Feedback for tabs behavior, navigation, style, etc label Jun 11, 2026

@ChristopherBiscardi ChristopherBiscardi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very cool, thanks for taking this on!


This definitely doesn't handle unicode codepoints correctly but notably it doesn't seem like any of the other already-existing truncation code does either, so I'm not going to consider it a blocker for this PR.


For the unicode issue, consider the following polar bear, which is the combination of a bear, a zero-width-joiner, and a snowflake.

aaaa🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️🐻‍❄️bbbbbbb.txt

When truncated, this splits the middle and results in each side of the emoji rendering.

image

@ChristopherBiscardi
ChristopherBiscardi added this pull request to the merge queue Jun 11, 2026
Merged via the queue into zed-industries:main with commit 03a8544 Jun 11, 2026
44 checks passed
cppcoffee pushed a commit to cppcoffee/zed that referenced this pull request Jun 15, 2026
Follow up to zed-industries#59072 adjusting
some UI design for the file finder that got regressed.

Release Notes:

- N/A
This was referenced Jun 18, 2026
@moechofe

Copy link
Copy Markdown

So, now the filename is truncated even if there is enough space for the name to be display entirely.
Doesn't seems to be the right move. IMHO
Screenshot from 2026-06-25 10-44-27
In this example, the file is MBKong.hpp, and g.h was removed.
In the changelog, it says: "... so extensions remain visible", but it's not true.

jonx pushed a commit to jonx/zed-aros that referenced this pull request Jul 17, 2026
…9072)

## Context

This follow-up was inspired by Christopher’s suggestion in the review
comment on zed-industries#58483: long filenames should truncate in the middle so both
the beginning and the suffix/extension remain visible.

Previously, very long filenames in picker rows could still be clipped or
end-truncated, making files with shared prefixes hard to distinguish.
This adds middle-truncation support to GPUI text overflow and applies it
to filename-focused picker surfaces: the tab switcher and the Ctrl-P
file finder. Normal editor tab bar behavior remains unchanged and
continues to use the existing title length cap.

## How to Review

- **`crates/gpui/src/style.rs`, `crates/gpui/src/styled.rs`,
`crates/gpui/src/elements/text.rs`,
`crates/gpui/src/text_system/line_wrapper.rs`**: Adds
`TextOverflow::TruncateMiddle`, wires it through text layout, and
implements middle truncation while preserving valid text runs. Very
narrow widths now show the truncation affix instead of falling back to
the abruptly clipped original text.

- **`crates/ui/src/components/label/label_like.rs`,
`crates/ui/src/components/label/label.rs`,
`crates/ui/src/components/label/highlighted_label.rs`**: Exposes middle
truncation through the shared label components.

- **`crates/workspace/src/item.rs`, `crates/editor/src/items.rs`,
`crates/workspace/src/pane.rs`,
`crates/tab_switcher/src/tab_switcher.rs`**: Adds an explicit
tab-content opt-in for middle truncation. The tab switcher enables it,
while the normal tab bar and dragged tabs keep their existing behavior.

- **`crates/file_finder/src/file_finder.rs`**: Applies middle truncation
to Ctrl-P file finder filenames and lets the path shrink from the start
so long paths do not hide important filename suffixes.

Manual test before change :

[Screencast from 2026-06-10
22-59-28.webm](https://github.com/user-attachments/assets/5e032646-a48c-45f2-8fe2-0424507fd576)

Manual test after change :

[Screencast from 2026-06-10
22-54-48.webm](https://github.com/user-attachments/assets/4b9253da-f169-4ed1-bdd5-ee71dcf49a83)


## Self-Review Checklist

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the UI/UX checklist
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Improved long filename truncation in the tab switcher and file finder
so extensions remain visible.
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
…9072)

## Context

This follow-up was inspired by Christopher’s suggestion in the review
comment on zed-industries#58483: long filenames should truncate in the middle so both
the beginning and the suffix/extension remain visible.

Previously, very long filenames in picker rows could still be clipped or
end-truncated, making files with shared prefixes hard to distinguish.
This adds middle-truncation support to GPUI text overflow and applies it
to filename-focused picker surfaces: the tab switcher and the Ctrl-P
file finder. Normal editor tab bar behavior remains unchanged and
continues to use the existing title length cap.

## How to Review

- **`crates/gpui/src/style.rs`, `crates/gpui/src/styled.rs`,
`crates/gpui/src/elements/text.rs`,
`crates/gpui/src/text_system/line_wrapper.rs`**: Adds
`TextOverflow::TruncateMiddle`, wires it through text layout, and
implements middle truncation while preserving valid text runs. Very
narrow widths now show the truncation affix instead of falling back to
the abruptly clipped original text.

- **`crates/ui/src/components/label/label_like.rs`,
`crates/ui/src/components/label/label.rs`,
`crates/ui/src/components/label/highlighted_label.rs`**: Exposes middle
truncation through the shared label components.

- **`crates/workspace/src/item.rs`, `crates/editor/src/items.rs`,
`crates/workspace/src/pane.rs`,
`crates/tab_switcher/src/tab_switcher.rs`**: Adds an explicit
tab-content opt-in for middle truncation. The tab switcher enables it,
while the normal tab bar and dragged tabs keep their existing behavior.

- **`crates/file_finder/src/file_finder.rs`**: Applies middle truncation
to Ctrl-P file finder filenames and lets the path shrink from the start
so long paths do not hide important filename suffixes.

Manual test before change :

[Screencast from 2026-06-10
22-59-28.webm](https://github.com/user-attachments/assets/5e032646-a48c-45f2-8fe2-0424507fd576)

Manual test after change :

[Screencast from 2026-06-10
22-54-48.webm](https://github.com/user-attachments/assets/4b9253da-f169-4ed1-bdd5-ee71dcf49a83)


## Self-Review Checklist

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the UI/UX checklist
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Improved long filename truncation in the tab switcher and file finder
so extensions remain visible.
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
Follow up to zed-industries#59072 adjusting
some UI design for the file finder that got regressed.

Release Notes:

- N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ui/tabs Feedback for tabs behavior, navigation, style, etc cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants