git_ui: Let branch and repo name use available panel width (#57502)

The git panel footer truncated branch and repo against a predefined
character budget. This PR improves that and lets both float free with
flex-based truncation.

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



Some examples.

<img width="738" height="1794" alt="Screenshot 2026-05-22 at 17 35 09"
src="https://github.com/user-attachments/assets/18a4873c-fbcf-4875-8d1a-82eaa2ce222c"
/>
<img width="1590" height="1562" alt="Screenshot 2026-05-22 at 17 35 15"
src="https://github.com/user-attachments/assets/c4adf7a3-e093-4104-af20-c098eda80c08"
/>
<img width="990" height="1570" alt="Screenshot 2026-05-22 at 17 28 20"
src="https://github.com/user-attachments/assets/eda0dd31-2461-4d4b-b63c-902c6c47231e"
/>
<img width="606" height="1640" alt="Screenshot 2026-05-22 at 17 28 12"
src="https://github.com/user-attachments/assets/4a165d75-93d3-45a4-9d8b-525c39f49493"
/>


Closes #57238

Release Notes:

- Fixed the git panel branch name staying truncated even when the panel
was wide enough to show the full name (#57238)
This commit is contained in:
Matei Oprea 2026-05-22 17:56:05 +03:00 committed by GitHub
parent dee596fa96
commit 949d993146
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6988,9 +6988,6 @@ impl RenderOnce for PanelRepoFooter {
.map(|project| project.read(cx).git_store().read(cx).repositories().len() == 1)
.unwrap_or(true);
const MAX_BRANCH_LEN: usize = 16;
const MAX_REPO_LEN: usize = 16;
const LABEL_CHARACTER_BUDGET: usize = MAX_BRANCH_LEN + MAX_REPO_LEN;
const MAX_SHORT_SHA_LEN: usize = 8;
let branch_name = self
.branch
@ -7010,36 +7007,6 @@ impl RenderOnce for PanelRepoFooter {
let active_repo_name = self.active_repository.clone();
let branch_actual_len = branch_name.len();
let repo_actual_len = active_repo_name.len();
// ideally, show the whole branch and repo names but
// when we can't, use a budget to allocate space between the two
let (repo_display_len, branch_display_len) =
if branch_actual_len + repo_actual_len <= LABEL_CHARACTER_BUDGET {
(repo_actual_len, branch_actual_len)
} else if branch_actual_len <= MAX_BRANCH_LEN {
let repo_space = (LABEL_CHARACTER_BUDGET - branch_actual_len).min(MAX_REPO_LEN);
(repo_space, branch_actual_len)
} else if repo_actual_len <= MAX_REPO_LEN {
let branch_space = (LABEL_CHARACTER_BUDGET - repo_actual_len).min(MAX_BRANCH_LEN);
(repo_actual_len, branch_space)
} else {
(MAX_REPO_LEN, MAX_BRANCH_LEN)
};
let truncated_repo_name = if repo_actual_len <= repo_display_len {
active_repo_name.to_string()
} else {
util::truncate_and_trailoff(active_repo_name.trim_ascii(), repo_display_len)
};
let truncated_branch_name = if branch_actual_len <= branch_display_len {
branch_name
} else {
util::truncate_and_trailoff(branch_name.trim_ascii(), branch_display_len)
};
let repo_selector = PopoverMenu::new("repository-switcher")
.menu({
let project = project;
@ -7049,7 +7016,7 @@ impl RenderOnce for PanelRepoFooter {
}
})
.trigger_with_tooltip(
Button::new("repo-selector", truncated_repo_name)
Button::new("repo-selector", active_repo_name)
.size(ButtonSize::None)
.label_size(LabelSize::Small)
.truncate(true),
@ -7068,7 +7035,7 @@ impl RenderOnce for PanelRepoFooter {
})
.into_any_element();
let branch_selector_button = Button::new("branch-selector", truncated_branch_name)
let branch_selector_button = Button::new("branch-selector", branch_name)
.size(ButtonSize::None)
.label_size(LabelSize::Small)
.truncate(true)
@ -7111,15 +7078,16 @@ impl RenderOnce for PanelRepoFooter {
},
))
.when(!single_repo, |this| {
this.child(repo_selector).when(show_separator, |this| {
this.child(
Label::new("/").size(LabelSize::Small).color(Color::Custom(
cx.theme().colors().text_muted.opacity(0.4),
)),
)
})
this.child(div().child(repo_selector).min_w_0()).when(
show_separator,
|this| {
this.child(Label::new("/").size(LabelSize::Small).color(
Color::Custom(cx.theme().colors().text_muted.opacity(0.4)),
))
},
)
})
.child(branch_selector),
.child(div().child(branch_selector).min_w_0()),
)
.children(if let Some(git_panel) = self.git_panel {
git_panel.update(cx, |git_panel, cx| git_panel.render_remote_button(cx))