From ac60a9c08cc67e93a11c6503abe11a00d1123771 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 12:23:00 -0800 Subject: [PATCH] Type: New in Kinsoku Shori Settings skips the names of the document's sets After Delete, New could give the new set the deleted set's name. With no `from`, OK then treated it as the deleted set, so that set's paragraphs took the new set's characters instead of Hard. New's default name now also skips every name the document's sets had when the dialog opened. --- crates/ui-egui/src/dialogs/kinsoku_sets.rs | 12 ++++++--- .../ui-egui/src/dialogs/kinsoku_sets/tests.rs | 26 +++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/dialogs/kinsoku_sets.rs b/crates/ui-egui/src/dialogs/kinsoku_sets.rs index 41d1b6d52b..668368e1b9 100644 --- a/crates/ui-egui/src/dialogs/kinsoku_sets.rs +++ b/crates/ui-egui/src/dialogs/kinsoku_sets.rs @@ -117,9 +117,12 @@ fn take_fields(d: &Dialog, set: &mut Map) { } } -/// "Kinsoku Set N", the first N no set in `sets` is named. -fn new_name(sets: &[Map]) -> String { - (1..).map(|n| format!("Kinsoku Set {n}")).find(|n| !sets.iter().any(|s| KinsokuSet::same_name(name_of(s), n))).unwrap_or_default() +/// "Kinsoku Set N", the first N that no set in `sets` and no set of the document (`doc`) is named. +/// A set Delete took out keeps its name out of New's, so OK gives its paragraphs Hard instead of +/// the new set's characters. +fn new_name(sets: &[Map], doc: &[KinsokuSet]) -> String { + let taken = |n: &str| sets.iter().any(|s| KinsokuSet::same_name(name_of(s), n)) || doc.iter().any(|k| KinsokuSet::same_name(&k.name, n)); + (1..).map(|n| format!("Kinsoku Set {n}")).find(|n| !taken(n)).unwrap_or_default() } /// The character `code` names: `U+3001`, `u+3001` or `3001`, in hexadecimal. @@ -253,7 +256,8 @@ fn run(app: &mut VectorcraftApp, d: &mut Dialog, act: Action) -> Result<(), Stri } }; set.remove("from"); - set.insert("name".into(), json!(new_name(&list))); + let doc = app.session.active().map(|t| t.doc.kinsoku_sets.to_vec()).unwrap_or_default(); + set.insert("name".into(), json!(new_name(&list, &doc))); list.push(set); put_sets(d, &list); select(d, list.len() - 1); diff --git a/crates/ui-egui/src/dialogs/kinsoku_sets/tests.rs b/crates/ui-egui/src/dialogs/kinsoku_sets/tests.rs index 04476280ab..c6d7363035 100644 --- a/crates/ui-egui/src/dialogs/kinsoku_sets/tests.rs +++ b/crates/ui-egui/src/dialogs/kinsoku_sets/tests.rs @@ -146,6 +146,32 @@ fn based_on_follows_a_renamed_set() { assert_eq!((d.str("name"), d.str("cannotStart")), ("Kinsoku Set 1".to_string(), "ゞ".to_string())); } +/// Delete then New does not give the new set the deleted set's name, so on OK the deleted set's +/// paragraphs take Hard rather than the new set's characters. +#[test] +fn new_after_delete_does_not_take_the_deleted_name() { + let mut app = app(); + app.run("type.kinsokuSets.set", json!({"sets": [{"name": "Kinsoku Set 1", "cannotStart": "ゝ"}]})).unwrap(); + let id = app.run("text.create", json!({"x": 10, "y": 50, "text": "あいう"})).unwrap()["id"].as_u64().unwrap(); + app.run("select.set", json!({"ids": [id]})).unwrap(); + app.run("text.setFormat", json!({"kinsoku": "Kinsoku Set 1"})).unwrap(); + open(&mut app).unwrap(); + frame(&mut app); + press(&mut app, Action::Delete); + dialog(&mut app).fields.insert("base".into(), json!("none")); + frame(&mut app); + press(&mut app, Action::New); + assert_eq!(dialog(&mut app).str("name"), "Kinsoku Set 2"); + frame(&mut app); + super::super::confirm(&mut app).unwrap(); + assert_eq!(doc_sets(&app).iter().map(|k| k.name.as_str()).collect::>(), ["Kinsoku Set 2"]); + let para = match &app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap().kind { + vectorcraft_doc::NodeKind::Text(t) => t.para_at(0).clone(), + _ => panic!("not text"), + }; + assert_eq!(para.kinsoku_name(), "Hard"); +} + /// OK takes the fields as they are set (`ui.dialog.set`) even when no frame was drawn since. Once /// `selected` picks another set, the fields no longer describe it: OK leaves that set as it is, /// and the next frame fills the fields from it.