fix: centralize chrome segment spacing

This commit is contained in:
2026-10-18 01:52:43 +02:00
parent d8cfd27ee6
commit a28444a9f2
5 changed files with 87 additions and 75 deletions
-1
View File
@@ -931,7 +931,6 @@ end
let loaded = load_config(&path).unwrap();
assert_eq!(loaded.top_bar.left, ["mode", "language"]);
assert_eq!(loaded.top_bar.segment("mode").padding, 0);
assert_eq!(loaded.top_bar.segment("language").padding, 1);
assert_eq!(loaded.bottom_bar.left, ["tabs"]);
assert_eq!(loaded.bottom_bar.segment("tabs").title, "{name}{modified}");
+72 -44
View File
@@ -4933,41 +4933,69 @@ fn native_lsp_names_are_borrowed_in_either_bar_and_ignore_configured_labels() {
}
#[test]
fn bottom_position_has_only_a_leading_margin_and_lsp_has_none() {
fn chrome_separates_visible_segments_once_in_every_anchor() {
let mut editor = Editor::open(None, vec![]).unwrap();
editor.set_lsp_names(vec!["server".into()]);
configure_chrome(&mut editor, |top, bottom| {
top.left.clear();
top.center.clear();
top.right = vec!["position".into()];
bottom.left.clear();
bottom.center.clear();
bottom.right = vec!["lsp".into(), "position".into()];
});
let mut terminal = Terminal::new(ratatui::backend::TestBackend::new(40, 2)).unwrap();
terminal
.draw(|frame| {
for (line, y) in [
(editor.top_bar_config(), 0),
(editor.bottom_bar_config(), 1),
] {
let groups = chrome_groups(&editor, line, &SyntaxCache::new());
let start = 40 - chrome_group_width(&groups[2]) as u16;
if y == 1 {
let gap = start + groups[2][0].width as u16;
draw_chrome(frame, groups, Rect::new(0, y, 40, 1));
assert_eq!(frame.buffer_mut()[(start, y)].bg, Color::Cyan);
assert_eq!(frame.buffer_mut()[(gap, y)].symbol(), " ");
assert_eq!(frame.buffer_mut()[(gap, y)].bg, Color::Reset);
assert_eq!(frame.buffer_mut()[(gap + 1, y)].symbol(), "░");
} else {
draw_chrome(frame, groups, Rect::new(0, y, 40, 1));
assert_eq!(frame.buffer_mut()[(start, y)].symbol(), "░");
for anchor in 0..3 {
configure_chrome(&mut editor, |top, bottom| {
for line in [top, bottom] {
line.left.clear();
line.center.clear();
line.right.clear();
let names = vec![
"before".into(),
"lsp".into(),
"after".into(),
"position".into(),
];
match anchor {
0 => line.left = names,
1 => line.center = names,
_ => line.right = names,
}
assert_eq!(frame.buffer_mut()[(39, y)].bg, Color::Cyan);
}
})
.unwrap();
});
editor
.set_label("before".into(), "Markdown".into())
.unwrap();
editor.set_label("after".into(), "tail".into()).unwrap();
for servers in [vec![], vec!["server".into()]] {
editor.set_lsp_names(servers);
let expected = if editor.lsp_label().is_empty() {
"Markdown tail ░▓ 1:1 "
} else {
"Markdown server tail ░▓ 1:1 "
};
let mut terminal = Terminal::new(ratatui::backend::TestBackend::new(50, 2)).unwrap();
terminal
.draw(|frame| {
for (line, y) in [
(editor.top_bar_config(), 0),
(editor.bottom_bar_config(), 1),
] {
draw_chrome(
frame,
chrome_groups(&editor, line, &SyntaxCache::new()),
Rect::new(0, y, 50, 1),
);
}
})
.unwrap();
let start = match anchor {
0 => 0,
1 => (50 - expected.width()) / 2,
_ => 50 - expected.width(),
};
for y in 0..2 {
assert_eq!(
pane_screen(
&terminal,
Rect::new(start as u16, y, expected.width() as u16, 1)
),
expected
);
}
}
}
}
#[test]
@@ -5855,8 +5883,8 @@ fn chrome_anchors_center_on_the_full_row_and_preserve_right_order() {
assert_eq!(buffer[(25, y)].symbol(), "I");
assert_eq!(buffer[(26, y)].symbol(), "D");
}
assert!(pane_screen(&terminal, Rect::new(0, 0, 51, 1)).ends_with("ABC"));
assert!(pane_screen(&terminal, Rect::new(3, 2, 45, 1)).ends_with("ABC"));
assert!(pane_screen(&terminal, Rect::new(0, 0, 51, 1)).ends_with("A BC"));
assert!(pane_screen(&terminal, Rect::new(3, 2, 45, 1)).ends_with("A BC"));
editor.set_label("left".into(), "L".repeat(30)).unwrap();
terminal
@@ -5876,7 +5904,7 @@ fn chrome_anchors_center_on_the_full_row_and_preserve_right_order() {
for (y, x, width) in [(0, 0, 51), (2, 3, 45)] {
let row = pane_screen(&terminal, Rect::new(x, y, width, 1));
assert!(!row.contains("MID"), "{row}");
assert!(row.ends_with("ABC"), "{row}");
assert!(row.ends_with("A BC"), "{row}");
}
}
@@ -6024,11 +6052,11 @@ fn chrome_uses_cell_widths_for_independent_edges_and_internal_padding() {
let buffer = terminal.backend().buffer();
for (x, text) in [
(2, "1"),
(5, "界"),
(7, "▌"),
(10, "2"),
(13, "▐"),
(14, "界"),
(6, "界"),
(8, "▌"),
(11, "2"),
(14, "▐"),
(15, "界"),
(29, "界"),
(31, "("),
(34, "e\u{301}"),
@@ -6051,9 +6079,9 @@ fn chrome_uses_cell_widths_for_independent_edges_and_internal_padding() {
assert_eq!(buffer[(x, 2)].bg, Color::Cyan);
}
assert_eq!(buffer[(2, 0)].bg, Color::Reset);
assert_eq!(buffer[(10, 0)].bg, Color::Cyan);
assert_eq!(buffer[(11, 0)].bg, Color::Cyan);
assert_eq!(buffer[(5, 0)].bg, Color::Reset);
for x in [8, 9, 11, 12, 32, 33, 35, 36] {
for x in [9, 10, 12, 13, 32, 33, 35, 36] {
assert_eq!(buffer[(x, 0)].symbol(), " ");
assert_eq!(buffer[(x, 0)].bg, Color::Cyan);
}
@@ -6071,8 +6099,8 @@ fn chrome_uses_cell_widths_for_independent_edges_and_internal_padding() {
assert_eq!(buffer[(0, 0)].symbol(), "<");
assert_eq!(buffer[(3, 0)].symbol(), "1");
assert_eq!(buffer[(3, 0)].bg, Color::Cyan);
assert_eq!(buffer[(11, 0)].symbol(), "2");
assert_eq!(buffer[(11, 0)].bg, Color::Reset);
assert_eq!(buffer[(12, 0)].symbol(), "2");
assert_eq!(buffer[(12, 0)].bg, Color::Reset);
}
#[test]