Kinsoku Shori Sets: show None when the set list is empty

This commit is contained in:
dotCooCoo
2026-11-26 06:36:33 -08:00
parent c8c4faa34a
commit e26efcb165
2 changed files with 18 additions and 2 deletions
+3 -2
View File
@@ -361,10 +361,11 @@ impl KinsokuDialog {
let rows: Vec<PresetRow<String>> = list.iter().map(|s| PresetRow::item(name_of(s).to_owned(), name_of(s), 0)).collect();
let mut value = list.get(self.index(list.len())).map(|s| name_of(s).to_owned());
let suggestion = new_name(&list, &self.opened);
// PLAN: PresetPicker has no placeholder: an empty list shows an empty name field, not "None".
let source = PresetSource::listed(&rows);
let refuses = |typed: &str| name_problem(&list, typed);
let picker = PresetPicker::new(tl!("Kinsoku Set"), Bind::bound(&mut value), &source, Bind::bound(&mut self.picker)).field(PickerField::Name);
let picker = PresetPicker::new(tl!("Kinsoku Set"), Bind::bound(&mut value), &source, Bind::bound(&mut self.picker))
.field(PickerField::Name)
.placeholder(tl!("None"));
let out = NamedPresetRow::new(tl!("Kinsoku Set"), picker).suggest_name(suggestion).check_name(NameCheck::of_host(&refuses)).show(ui);
self.apply(out.events);
@@ -47,6 +47,21 @@ fn cancel(app: &VectorcraftApp) {
app.dialogs().unwrap().with(|h| h.cancel::<KinsokuDialog>(&ctx));
}
#[test]
fn empty_kinsoku_list_shows_none_in_the_preset_picker() {
let mut fixture = craft::ui::testing::Fixture::new(|ui| crate::dialogs::host::window_dialogs(ui.ctx()).with(|host| host.run(ui)));
fixture.room(egui::vec2(800.0, 600.0));
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.ui_ctx = Some(fixture.ctx().clone());
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
open(&mut app).unwrap();
fixture.settle();
let picker = fixture.by_label("Kinsoku Set").expect("Kinsoku Set picker");
assert_eq!(fixture.tree().value_of(picker.node), Some("None"));
assert!(picked(&app).is_empty(), "the caption does not select a set");
}
/// Type › Kinsoku Shori Settings… opens on the document's sets; New adds one based on Hard, its
/// categories edited in their fields and Add putting in a character by its code point; nothing
/// changes until OK, which sets them as one undo step; Cancel leaves them.