moveSelection walks the snapshot to find the current selection, then shifts it by delta (clamped). The snapshot is small (≤500) so a linear scan is fine; the alternative is tracking an index that drifts as the ring rolls.
(delta int)
| 753 | // scan is fine; the alternative is tracking an index that drifts as the |
| 754 | // ring rolls. |
| 755 | func (m *harness) moveSelection(delta int) { |
| 756 | events := debug.Snapshot() |
| 757 | if len(events) == 0 { |
| 758 | return |
| 759 | } |
| 760 | idx := len(events) - 1 // default to latest if current selection is gone |
| 761 | for i, e := range events { |
| 762 | if e.ID == m.debugSelected { |
| 763 | idx = i |
| 764 | break |
| 765 | } |
| 766 | } |
| 767 | idx += delta |
| 768 | if idx < 0 { |
| 769 | idx = 0 |
| 770 | } |
| 771 | if idx >= len(events) { |
| 772 | idx = len(events) - 1 |
| 773 | } |
| 774 | m.debugSelected = events[idx].ID |
| 775 | } |
| 776 | |
| 777 | // mouseSelect maps a left-click Y coordinate onto the debug panel and, if it |
| 778 | // lands on an event row, focuses the panel and selects that event. |
no test coverage detected