Skip to content

Commit c9f76e7

Browse files
authored
Merge pull request #13134 from gitbutlerapp/dp/wpmnmvrpoyzs
Fix another flaky tui test
2 parents 214dbb3 + 7feecb8 commit c9f76e7

5 files changed

Lines changed: 61 additions & 38 deletions

crates/but/src/command/legacy/status/tui/tests/snapshots/commit_file_list_rub_can_escape_scope_and_esc_reenters_file_list_final.svg

Lines changed: 2 additions & 2 deletions
Loading

crates/but/src/command/legacy/status/tui/tests/snapshots/commit_file_list_scopes_cursor_to_files_in_selected_commit_final.svg

Lines changed: 2 additions & 2 deletions
Loading

crates/but/src/command/legacy/status/tui/tests/snapshots/global_file_list_does_not_restrict_cursor_final.svg

Lines changed: 4 additions & 4 deletions
Loading

crates/but/src/command/legacy/status/tui/tests/snapshots/rubbing_003.svg

Lines changed: 2 additions & 2 deletions
Loading

crates/but/src/command/legacy/status/tui/tests/utils.rs

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -345,41 +345,64 @@ fn volatile_id_hex_prefix_cell(
345345

346346
let row_start = area.x;
347347
let row_end = area.x.saturating_add(area.width);
348-
let search_start = x.saturating_sub(1).max(row_start);
348+
let is_blue_bold = |cell: &ratatui::buffer::Cell| {
349+
matches!(cell.fg, Color::Blue) && cell.modifier.contains(Modifier::BOLD)
350+
};
349351

350-
for start in search_start..=x {
351-
let Some(end) = start.checked_add(4) else {
352-
continue;
353-
};
354-
if end >= row_end {
355-
continue;
352+
let mut hex_start = x;
353+
while hex_start > row_start {
354+
let prev_x = hex_start.saturating_sub(1);
355+
let prev_cell = &buffer[(prev_x, y)];
356+
if !is_blue_bold_hex_cell(prev_cell) {
357+
break;
356358
}
359+
hex_start = prev_x;
360+
}
357361

358-
let first = &buffer[(start, y)];
359-
let second = &buffer[(start.saturating_add(1), y)];
360-
let colon = &buffer[(start.saturating_add(2), y)];
361-
let v = &buffer[(start.saturating_add(3), y)];
362-
let o = &buffer[(start.saturating_add(4), y)];
362+
let mut hex_end = x;
363+
while hex_end.saturating_add(1) < row_end {
364+
let next_x = hex_end.saturating_add(1);
365+
let next_cell = &buffer[(next_x, y)];
366+
if !is_blue_bold_hex_cell(next_cell) {
367+
break;
368+
}
369+
hex_end = next_x;
370+
}
363371

364-
let is_blue_bold = |cell: &ratatui::buffer::Cell| {
365-
matches!(cell.fg, Color::Blue) && cell.modifier.contains(Modifier::BOLD)
366-
};
372+
if hex_end == hex_start {
373+
return false;
374+
}
367375

368-
if is_blue_bold_hex_cell(first)
369-
&& is_blue_bold_hex_cell(second)
370-
&& is_blue_bold(colon)
371-
&& colon.symbol() == ":"
372-
&& is_blue_bold(v)
373-
&& v.symbol() == "v"
374-
&& is_blue_bold(o)
375-
&& o.symbol() == "o"
376-
&& x <= start.saturating_add(1)
377-
{
378-
return true;
379-
}
376+
let Some(colon_x) = hex_end.checked_add(1) else {
377+
return false;
378+
};
379+
let Some(label_first_x) = hex_end.checked_add(2) else {
380+
return false;
381+
};
382+
let Some(label_second_x) = hex_end.checked_add(3) else {
383+
return false;
384+
};
385+
if label_second_x >= row_end {
386+
return false;
387+
}
388+
389+
let colon = &buffer[(colon_x, y)];
390+
if !is_blue_bold(colon) || colon.symbol() != ":" {
391+
return false;
380392
}
381393

382-
false
394+
let label_first = &buffer[(label_first_x, y)];
395+
let label_second = &buffer[(label_second_x, y)];
396+
let is_blue_bold_lower = |cell: &ratatui::buffer::Cell| {
397+
is_blue_bold(cell)
398+
&& cell
399+
.symbol()
400+
.chars()
401+
.next()
402+
.is_some_and(|c| c.is_ascii_lowercase())
403+
};
404+
405+
is_blue_bold_lower(label_first) && is_blue_bold_lower(label_second)
383406
}
384407

385408
fn color_to_rgb(color: Color, default: (u8, u8, u8)) -> (u8, u8, u8) {

0 commit comments

Comments
 (0)