mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
Fix blank gaps and backgrounds in TUI flex rows (#64775)
## Why Blank gaps in nested rows can shift end-aligned text when a row is clipped. Blank lines can also lose their inline code or flex background. ## What changed Suppress unpainted gaps on blank lines in aligned rows while preserving spacer padding that clipping can reclaim for the ellipsis. Paint inline code gaps and fill explicit flex backgrounds through the visible height of stretched bands. ## Testing Add rendering regressions for clipped end alignment, ellipsis placement next to a wide glyph, and background coverage on blank lines. GitOrigin-RevId: 2fc9d4b651dbf8a3cd8f63867bc6730a3bebd3ac
This commit is contained in:
@@ -175,7 +175,8 @@ fn layout_band<'a>(
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let suppress_blank = aligned && !width.in_aligned_row && background_width == 0;
|
||||
let painted_gap = background_width > 0 || paint.gap.inline_code;
|
||||
let suppress_blank = (aligned || width.in_aligned_row) && !painted_gap;
|
||||
let placements = children.iter().map(move |child| {
|
||||
let minimum = bounded(child.widths.minimum);
|
||||
reserved -= minimum;
|
||||
@@ -271,7 +272,7 @@ fn layout_band<'a>(
|
||||
*end = padding;
|
||||
}
|
||||
if start > *end {
|
||||
emit(if background_width > 0 {
|
||||
emit(if painted_gap {
|
||||
Fragment::Background(start - *end, &paint.gap)
|
||||
} else {
|
||||
Fragment::Gap(start - *end, &paint.gap)
|
||||
@@ -293,11 +294,27 @@ fn layout_band<'a>(
|
||||
layout_node(child, child_width, limit, &mut place);
|
||||
}
|
||||
}
|
||||
// A visible sibling may need to reclaim spacer padding for the ellipsis.
|
||||
// Forward through the last elastic cell, leaving trailing empty gaps suppressed.
|
||||
if width.in_aligned_row && suppress_blank {
|
||||
for (y, (_, pending)) in lines.iter().enumerate() {
|
||||
if let Some(parts) = pending
|
||||
&& let Some(last) = parts
|
||||
.iter()
|
||||
.rposition(|p| matches!(p, Fragment::Padding(..)))
|
||||
{
|
||||
for &part in &parts[..=last] {
|
||||
visit(y, part);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Fill the rest of each visible line of an explicitly colored flex item,
|
||||
// including blank continuations. Never take cells from the next sibling.
|
||||
if background_width > 0 {
|
||||
for (y, (end, _)) in lines.iter().enumerate() {
|
||||
if *end < background_width {
|
||||
for y in 0..lines.len().max(band_height.min(limit)) {
|
||||
let end = lines.get(y).map_or(0, |(end, _)| *end);
|
||||
if end < background_width {
|
||||
visit(
|
||||
y,
|
||||
Fragment::Background(background_width - end, &paint.leading),
|
||||
|
||||
@@ -1520,6 +1520,72 @@ fn trailing_gap_keeps_the_aligned_glyph_at_the_viewport_edge() {
|
||||
assert_eq!(painted_rows(&node, Size::new(4, 2)), [" 界", "1234"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn blank_wrapped_band_keeps_spacer_padding_for_clipping() {
|
||||
let node = tree(
|
||||
json!({"type":"row","props":{"gap":0,"justify":"end"},"children":[
|
||||
{"type":"row","props":{"gap":1,"wrap":"wrap"},"children":[
|
||||
{"type":"spacer"},{"type":"text","children":["\n\n"]},"xx"
|
||||
]}, "界"
|
||||
]}),
|
||||
);
|
||||
assert_eq!(painted_rows(&node, Size::new(4, 1)), [" 界…"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_blank_nested_gap_retains_its_inline_code_surface() {
|
||||
let node = tree(
|
||||
json!({"type":"row","props":{"gap":0,"justify":"end"},"children":[
|
||||
{"type":"code","children":[{"type":"row","props":{"gap":1},"children":[
|
||||
{"type":"text","children":["\n\n"]},{"type":"text","children":["\n\n"]}
|
||||
]}]}, "A"
|
||||
]}),
|
||||
);
|
||||
let area = Rect::new(0, 0, 2, 2);
|
||||
let mut buf = Buffer::empty(area);
|
||||
let mut theme = Theme::default();
|
||||
theme.settings.line_highlight = Some(syntect::highlighting::Color {
|
||||
r: 3,
|
||||
g: 0,
|
||||
b: 0,
|
||||
a: 0,
|
||||
});
|
||||
node.render(area, &theme, &mut buf, /*plain_style*/ None);
|
||||
for y in 0..2 {
|
||||
assert_eq!(buf[(0, y)].bg, ratatui::style::Color::Yellow);
|
||||
assert_eq!(buf[(1, y)].bg, ratatui::style::Color::Reset);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stretched_wrapped_band_fills_the_last_background_cell() {
|
||||
let spacer = json!({"type":"spacer"});
|
||||
let inner = json!({"type":"row","props":{"gap":0,"wrap":"wrap","background":"red"},"children":["A",spacer,"B",spacer,"C"]});
|
||||
let node = tree(json!({"type":"row","props":{"gap":0},"children":[inner,"1\n2\n3\n4\n5\n6"]}));
|
||||
let area = Rect::new(0, 0, 2, 6);
|
||||
let mut buf = Buffer::empty(area);
|
||||
node.render(area, &Theme::default(), &mut buf, /*plain_style*/ None);
|
||||
for y in 0..6 {
|
||||
assert_eq!(buf[(0, y)].bg, ratatui::style::Color::Red);
|
||||
assert_eq!(buf[(1, y)].bg, ratatui::style::Color::Reset);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_blank_nested_gap_does_not_shift_text_when_clipped() {
|
||||
let node = tree(json!({
|
||||
"type":"row","props":{"gap":0,"justify":"end"},"children":[
|
||||
"A",
|
||||
{"type":"row","props":{"gap":1},"children":[
|
||||
{"type":"text","children":["\n\n"]},
|
||||
{"type":"text","children":["\n\n"]}
|
||||
]}
|
||||
]
|
||||
}));
|
||||
assert_eq!(painted_rows(&node, Size::new(4, 2)), [" A", ""]);
|
||||
assert_eq!(painted_rows(&node, Size::new(4, 1)), [" A…"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested_row_background_fills_blank_lines_independently_of_siblings() {
|
||||
let area = Rect::new(0, 0, 8, 4);
|
||||
|
||||
Reference in New Issue
Block a user