Panics · P13 Lists: a directory selection gone from its entries picks none

This commit is contained in:
ZacharyZhang-NY committed 2026-10-06 17:41:53 -04:00
1 parent 4a05c12889
commit f2fc17118c
2 files changed
+23 -7

No files matched your search

+21 -6
View File
@@ -152,11 +152,17 @@ impl DirectoryListing {
/// The entry picked, by name.
pub fn selected(mut self, name: impl Into<SharedString>) -> 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<DirEntry>) -> Vec<String> {
entries
+2 -1
View File
@@ -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.