Widen sidebar tab close targets in the TUI (#63189)

## Why

Closing a sidebar tab with the mouse requires hitting a single terminal cell.

## What changed

Make the `×` and the cell on either side a three-column close target that
highlights as a unit on hover. Use spare space to widen tabs where possible
while preserving the number of visible tabs.

## Testing

Extend the side-chat interaction test to check hover styling across the
close target and verify that clicking either adjacent cell closes the tab.
Update snapshots for the new spacing and label truncation.

GitOrigin-RevId: f097eee9d613a09c511fa14f1af160c7416fe3aa
This commit is contained in:
Felipe Coury
2026-11-22 20:52:41 +00:00
committed by copyberry
parent 27cfadaf85
commit ba1c17f960
13 changed files with 44 additions and 47 deletions
@@ -464,7 +464,7 @@ async fn document_preview_scenario() -> Result<()> {
.collect::<Vec<_>>()
.join("\n");
insta::assert_snapshot!(preview, @"
guide.md × main.rs × +
guide.md × main.rs × +
3 let value = 3; ↑
↑/↓ read · f3 find · Tab link · f8 select · Esc clear highlight
");
@@ -649,7 +649,7 @@ size 123
.sidebar_tab_strip()
.expect("tab strip");
let narrow_labels = visible_sidebar_row(&tui, strip, strip.y);
insta::assert_snapshot!(narrow_labels, @"‹ fe…eA/g…md× fe…eB/g…md× +");
insta::assert_snapshot!(narrow_labels, @"‹ f…eA/g…d × f…eB/g…d × +");
let long_file = "Before the fold.\n\n".repeat(24);
for directory in ["feature-alpha-build", "feature-beta-build"] {
std::fs::create_dir_all(dir.path().join(directory))?;
@@ -676,7 +676,7 @@ size 123
.sidebar_tab_strip()
.expect("tab strip");
let narrow_labels = visible_sidebar_row(&tui, strip, strip.y);
insta::assert_snapshot!(narrow_labels, @"‹ 1:f…ld/g…d× 2:f…ld/g…d× +");
insta::assert_snapshot!(narrow_labels, @"‹ 1:f…d/…d × 2:f…d/…d × +");
// If resolution itself fails, there is no new tab in which to show the path.
let tab_count = app.sidebar().unwrap().documents.len();
app.open_document(
@@ -2,7 +2,7 @@
source: tui/src/app/sidebar_document_tests.rs
expression: visible
---
‹ 1:f…ld/g…d× 2:f…ld/g…d× +
‹ 1:f…ld/g…d × 2:f…ld/g…d × +
Before the fold. ↑
Before the fold.
@@ -3,6 +3,6 @@ source: tui/src/app/sidebar_open_in_codex_tests.rs
assertion_line: 341
expression: sidebar.trim_end()
---
Side chat × PLAN.md × Agent transcript × note.md × +
Side chat × PLAN.md × Agent transcript × note.md × +
Open <workspace>/note.md?
Focus this pane and press Enter to open.
@@ -2,7 +2,7 @@
source: tui/src/app/sidebar_open_in_codex_tests.rs
expression: sidebar.trim_end()
---
PLAN.md × +
PLAN.md × +
Snapshot · Enter to open live
Use the sidebar. ↑
@@ -1,8 +1,8 @@
---
source: tui/src/app/sidebar_agent_status_tests.rs
expression: "screen.replace(&child.to_string(), \"[agent id]\")"
expression: "crate::chatwidget::tests::helpers::normalize_agent_center_snapshot(screen.replace(&child.to_string(),\n\"[agent id]\"))"
---
│ reviewer × +
│ reviewer × +
>_ OpenAI Codex (v0.0.0) │esc back to agents · Watch only
/tmp/project │
│ >_ OpenAI Codex (v0.0.0)
@@ -2,4 +2,4 @@
source: tui/src/app/tests.rs
expression: header.trim_end()
---
‹ Fix cache × +
‹ Fix cache × +
+11 -5
View File
@@ -5394,7 +5394,7 @@ async fn handle_start_side_seeds_navigation_before_thread_started() -> Result<()
let header = frame.lines().next().unwrap().split_once('│').unwrap().1;
insta::assert_snapshot!(
header.split_inclusive('×').take(2).collect::<String>(),
@" ☁️ Investigate…× ☁️ Fix cache ×"
@" ☁️ Investigate… × ☁️ Fix cache ×"
);
keys!(prefix, chooser_key);
let frame = side_frame(&mut app, &mut tui, even)?;
@@ -5582,7 +5582,7 @@ async fn handle_start_side_seeds_navigation_before_thread_started() -> Result<()
.collect::<Vec<_>>()
.try_into()
.expect("both side-chat tabs are visible");
assert_eq!(selected.x, inactive.right() + 2);
assert_eq!(selected.x, inactive.right() + 4);
assert_eq!(inactive.width, selected.width);
let [inactive, selected] = [inactive, selected].map(|area| area.x + 1);
for (state, column, row, palette, redraw) in [
@@ -5680,11 +5680,17 @@ async fn handle_start_side_seeds_navigation_before_thread_started() -> Result<()
let close_x = (chooser.x..chooser.right())
.rfind(|&x| tui.terminal.previous_buffer()[(x, chooser.y)].symbol() == "×")
.expect("close button on the second tab");
let hover = mouse(MouseEventKind::Moved, close_x - 1, chooser.y);
boxed_future!(app.handle_tui_event(&mut tui, &mut app_server, hover)).await?;
side_frame(&mut app, &mut tui, even)?;
let buffer = tui.terminal.previous_buffer();
let style = |x| buffer[(x, chooser.y)].style();
assert_eq!([close_x - 1, close_x + 1].map(style), [style(close_x); 2]);
for kind in [down, release] {
boxed_future!(app.handle_tui_event(
&mut tui,
&mut app_server,
mouse(kind, close_x, chooser.y)
mouse(kind, close_x + 1, chooser.y)
))
.await?;
}
@@ -5704,7 +5710,7 @@ async fn handle_start_side_seeds_navigation_before_thread_started() -> Result<()
boxed_future!(app.handle_tui_event(
&mut tui,
&mut app_server,
mouse(kind, close_x - 1, chooser.y)
mouse(kind, close_x - 2, chooser.y)
))
.await?;
}
@@ -5730,7 +5736,7 @@ async fn handle_start_side_seeds_navigation_before_thread_started() -> Result<()
boxed_future!(app.handle_tui_event(
&mut tui,
&mut app_server,
mouse(kind, close_x, chooser.y)
mouse(kind, close_x - 1, chooser.y)
))
.await?;
}
+16 -25
View File
@@ -19,6 +19,7 @@ pub(crate) enum SidebarTab {
/// Adjacent tabs have one unpainted, noninteractive terminal column between them.
const TAB_GAP: u16 = 1;
const CLOSE_WIDTH: u16 = 3;
const MIN_TAB_WIDTH: u16 = 12;
const MAX_TAB_WIDTH: u16 = 22;
@@ -64,6 +65,9 @@ impl<'a, Id: Copy + Eq> TabStrip<'a, Id> {
let space = available - 2 * gutter;
let width = space.min(preferred);
let count = usize::from((space + TAB_GAP) / (width + TAB_GAP)).min(self.ids.len());
// Use spare space for the extra close cells without reducing the number of tabs.
let room_per_tab = (space + TAB_GAP) / count as u16 - TAB_GAP;
let width = (width + CLOSE_WIDTH - 1).min(room_per_tab);
let start = self
.selected_index()
.map_or(0, |index| (index + 1).saturating_sub(count));
@@ -80,7 +84,7 @@ impl<'a, Id: Copy + Eq> TabStrip<'a, Id> {
}
let mut x = gutter;
for &id in &self.ids[start..end] {
let close = u16::from(width >= 3);
let close = CLOSE_WIDTH * u16::from(width > CLOSE_WIDTH);
let label = width - close;
targets.push((TabTarget::Tab(id), rect(x, label)));
if close > 0 {
@@ -133,32 +137,19 @@ impl<'a, Id: Copy + Eq> TabStrip<'a, Id> {
let targets = self.strip_targets(area);
for &(target, rect) in &targets {
let hovered = pointer.is_some_and(|point| rect.contains(point));
let quiet = if hovered { hover } else { rest };
let tab_style = |id| match (
Some(id) == self.selected && selected_state != TabState::Absent,
hovered,
) {
(true, true) => crate::style::hover_style(selected_style),
(true, false) => selected_style,
(false, true) => hover,
(false, false) => rest,
};
match target {
TabTarget::Tab(id) => {
let tab_style =
if Some(id) == self.selected && selected_state != TabState::Absent {
if hovered {
crate::style::hover_style(selected_style)
} else {
selected_style
}
} else {
quiet
};
paint(id, rect, tab_style, buf);
}
TabTarget::Tab(id) => paint(id, rect, tab_style(id), buf),
TabTarget::Close(id) => {
let close = if Some(id) == self.selected && selected_state != TabState::Absent {
if hovered {
crate::style::hover_style(selected_style)
} else {
selected_style
}
} else {
quiet
};
Line::from("×").style(close).render(rect, buf);
Line::from(" × ").style(tab_style(id)).render(rect, buf);
}
TabTarget::Overflow { glyph, .. } => {
let arrow = if hovered {
@@ -23,7 +23,7 @@ parent-29
New activity · esc latest
100 columns, reopened
parent-24 │ Side chat × +
parent-24 │ Side chat × +
│
parent-25 │child-25
│
@@ -43,7 +43,7 @@ parent-29 │child-29
│
99 columns, reopened
Side chat × +
Side chat × +
child-25
@@ -3,7 +3,7 @@ source: tui/src/app/tests.rs
expression: "format!(\"Zoomed\\n{zoomed}\\nRestored\\n{restored}\\nEqualized\\n{equalized}\")"
---
Zoomed
Side chat × +
Side chat × +
• unfinished answer
@@ -22,7 +22,7 @@ Zoomed
GPT-6.2-Sol default · Agent
tab to queue message · Side from main thread · ⌃/ to switch · ⌃c to close
Restored
parent-24 │ Side chat × +
parent-24 │ Side chat × +
│• unfinished answer
parent-25 │
│
@@ -41,7 +41,7 @@ parent-29
GPT-6.2-Sol default │ GPT-6.2-Sol default · Agent
│ tab to queue message · Side from main thread · ⌃/ to switch · ⌃c to close
Equalized
parent-24 │ Side chat × +
parent-24 │ Side chat × +
│• unfinished answer
parent-25 │
│
@@ -2,4 +2,4 @@
source: tui/src/app/tests.rs
expression: header.trim_end()
---
Investigate re…× Fix cache × +
Investigate re… × Fix cache × +
@@ -2,7 +2,7 @@
source: tui/src/app/tests.rs
expression: "chooser.lines().filter_map(|line|\nline.split_once('│').map(|(_, sidebar)|\nsidebar.trim_end())).collect::<Vec<_>>().join(\"\\n\")"
---
Side chat × +
Side chat × +
Open in sidebar
@@ -2,7 +2,7 @@
source: tui/src/app/tests.rs
expression: panel
---
parent-24 │ Side chat × +
parent-24 │ Side chat × +
│child-24
parent-25 │
│child-25