🟢 [L3] 颜色向后循环不 wrap #29

Closed
opened 2026-06-03 13:54:28 +08:00 by dailz · 1 comment
Owner

文件: tui/app.rs:657-678
分类: 状态机 / UI

问题: saturating_sub(1).min(colors.len()-1) 到 0 就停了,向左循环不 wrap 到最后一个颜色。

建议修复: 使用 (p + colors.len() - 1) % colors.len()

**文件**: `tui/app.rs:657-678` **分类**: 状态机 / UI **问题**: `saturating_sub(1).min(colors.len()-1)` 到 0 就停了,向左循环不 wrap 到最后一个颜色。 **建议修复**: 使用 `(p + colors.len() - 1) % colors.len()`。
dailz added the area/tuiseverity/lowbug labels 2026-06-03 13:54:28 +08:00
dailz closed this issue 2026-06-11 15:05:52 +08:00
Author
Owner

已修复: dfc016c

根因: cycle_color 向后循环使用 saturating_sub(1).min(colors.len()-1),到索引 0 时被钳位为 0,无法 wrap 到最后一个颜色。

修复: 替换为 if p == 0 { colors.len() - 1 } else { p - 1 },显式处理边界 wrap。

测试: 在 test_settings_cycle_color 中新增 2 个断言覆盖 wrap 边界(red→Left→white, white→Right→red),全部 10 个 settings 测试通过。

**已修复**: dfc016c 根因: `cycle_color` 向后循环使用 `saturating_sub(1).min(colors.len()-1)`,到索引 0 时被钳位为 0,无法 wrap 到最后一个颜色。 修复: 替换为 `if p == 0 { colors.len() - 1 } else { p - 1 }`,显式处理边界 wrap。 测试: 在 `test_settings_cycle_color` 中新增 2 个断言覆盖 wrap 边界(red→Left→white, white→Right→red),全部 10 个 settings 测试通过。
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dailz/logViewer#29