fix(tui): wrap color backward cycle at index 0 instead of clamping (closes #29)

This commit is contained in:
dailz
2026-06-11 15:05:42 +08:00
parent 19a3b877f9
commit dfc016c348

View File

@@ -757,7 +757,7 @@ impl App {
if forward {
(p + 1) % colors.len()
} else {
p.saturating_sub(1).min(colors.len() - 1)
if p == 0 { colors.len() - 1 } else { p - 1 }
}
}
None => {
@@ -1936,6 +1936,14 @@ plain text line
app.handle_key(make_key(crossterm::event::KeyCode::Left));
assert_eq!(app.settings_draft.error, "red");
// backward wrap: red (index 0) → white (index 7)
app.handle_key(make_key(crossterm::event::KeyCode::Left));
assert_eq!(app.settings_draft.error, "white");
// forward wrap: white (index 7) → red (index 0)
app.handle_key(make_key(crossterm::event::KeyCode::Right));
assert_eq!(app.settings_draft.error, "red");
}
#[test]