From f2fc17118caba2967029d76fa827f2630cb3764a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Tue, 6 Oct 2026 17:41:53 -0400 Subject: [PATCH] =?UTF-8?q?Panics=20=C2=B7=20P13=20Lists:=20a=20directory?= =?UTF-8?q?=20selection=20gone=20from=20its=20entries=20picks=20none?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lists/directory.rs | 27 +++++++++++++++++++++------ tasks/panics.md | 3 ++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/lists/directory.rs b/src/lists/directory.rs index a06fff6..288512c 100644 --- a/src/lists/directory.rs +++ b/src/lists/directory.rs @@ -152,11 +152,17 @@ impl DirectoryListing { /// The entry picked, by name. pub fn selected(mut self, name: impl Into) -> Self { let name = name.into(); - assert!( - self.entries.iter().any(|entry| entry.name == name), - "no entry {name}" - ); - self.selected = Some(name); + self.selected = self + .entries + .iter() + .any(|entry| entry.name == name) + .then(|| name.clone()); + if self.selected.is_none() { + log::error!( + "directory listing {:?}: no entry {name}; none picked", + self.id + ); + } self } @@ -350,7 +356,16 @@ impl RenderOnce for DirectoryListing { mod tests { use jiff::Timestamp; - use super::{Column, DirEntry, sorted}; + use super::{Column, DirEntry, DirectoryListing, sorted}; + + #[test] + fn a_selected_name_gone_from_the_entries_picks_none() { + let entries = || [DirEntry::file("a.txt", 1, Timestamp::UNIX_EPOCH)]; + let gone = DirectoryListing::new("dir", ["home"], entries()).selected("b.txt"); + assert_eq!(gone.selected, None); + let kept = DirectoryListing::new("dir", ["home"], entries()).selected("a.txt"); + assert_eq!(kept.selected.as_deref(), Some("a.txt")); + } fn names(entries: Vec) -> Vec { entries diff --git a/tasks/panics.md b/tasks/panics.md index 675ef1c..83b3521 100644 --- a/tasks/panics.md +++ b/tasks/panics.md @@ -27,7 +27,7 @@ Each item reads every site in its folders, fixes what the rules name, updates ca - [x] P10 Feedback — `src/feedback` - [x] P11 Loading & Motion — `src/motion` - [x] P12 Data Display — `src/data_display` -- [ ] P13 Lists & Trees — `src/lists` +- [x] P13 Lists & Trees — `src/lists` - [ ] P14 Tables — `src/tables` - [ ] P15 Charts — `src/charts` - [ ] P16 Finance — `src/finance` @@ -77,3 +77,4 @@ One line per item: what changed, what stayed and why, review rounds. - P10: no change. Kept: a toast's stay above zero (one value). Review: 1 round. - P11: a buffer at or behind the value draws none; `slide` was fixed in P05. Kept: values in 0..=1, segment and skeleton counts (one value each), builder misuse, reorder's permutation. Review: 1 round. - P12: a featured column past the columns features none; a gauge past its scale pegs; usage parts past the total fill it and repeat hues past eight; stars above max log and fill. Kept: one-value contracts, a comparison row's shape, construction. Review: 3 rounds (round 2 met an edit that had not applied). +- P13: a directory listing's selected name gone from its entries picks none. Kept: one-value contracts; activation, folder split, single-select sections and tree rows hold by construction. Review: 1 round.