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.
This commit is contained in:
dotCooCoo
2026-11-14 12:23:00 -08:00
parent f54b4e7ee1
commit ac60a9c08c
2 changed files with 34 additions and 4 deletions
+8 -4
View File
@@ -117,9 +117,12 @@ fn take_fields(d: &Dialog, set: &mut Map<String, Value>) {
}
}
/// "Kinsoku Set N", the first N no set in `sets` is named.
fn new_name(sets: &[Map<String, Value>]) -> 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<String, Value>], 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);
@@ -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::<Vec<_>>(), ["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.