fix(tui): wrap color backward cycle at index 0 instead of clamping (closes #29)
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user