From dfc016c348bea6e4d1a639f3e8f201cb8ebc248f Mon Sep 17 00:00:00 2001 From: dailz Date: Thu, 11 Jun 2026 15:05:42 +0800 Subject: [PATCH] fix(tui): wrap color backward cycle at index 0 instead of clamping (closes #29) --- crates/tui/src/app.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/tui/src/app.rs b/crates/tui/src/app.rs index 68cf869..ff79d16 100644 --- a/crates/tui/src/app.rs +++ b/crates/tui/src/app.rs @@ -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]