From d4cd3f2c485f79c02c43d1a87cf21dba7e970302 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 19:52:46 -0800 Subject: [PATCH] Tests: the missing-font question's tests check the open question and the clicked caret An answer that names another question, Cancel or OK, now has to leave the open question answerable: the right token's OK still starts the edit at the clicked character. The canvas double-click lands a quarter of the way into the text, and after OK the caret has to be the one a click at that point puts in the type being edited. --- crates/tools/src/text/tests.rs | 13 ++++++++++++- crates/ui-egui/src/canvas/tests.rs | 7 ++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/tools/src/text/tests.rs b/crates/tools/src/text/tests.rs index 7ee90ee1c8..249bf9d412 100644 --- a/crates/tools/src/text/tests.rs +++ b/crates/tools/src/text/tests.rs @@ -2273,7 +2273,8 @@ fn the_answer_to_the_missing_font_question_passes_the_option_check() { } /// Cancel starts no edit, and the edit in progress on other type goes on; an answer that names -/// another question, or one given to a document changed since, starts nothing either. +/// another question, or one given to a document changed since, starts nothing either. An answer +/// naming another question leaves the open question as it was. #[test] fn cancel_or_a_stale_answer_starts_no_edit_in_missing_fonts() { let (mut d, first, mut tool) = editing("First"); @@ -2296,6 +2297,16 @@ fn cancel_or_a_stale_answer_starts_no_edit_in_missing_fonts() { assert!(tool.poll(&changed, false).is_empty()); assert_eq!(tool.editing, Some(first)); assert!(!tool.waiting()); + // An answer naming another question leaves the open one answerable: its OK still starts the edit. + let (token, _) = asked(&click(&mut tool, &c, at.x, at.y)); + tool.set_option("missingFontEdit", &json!({"token": token + 1, "ok": false})); + tool.set_option("missingFontEdit", &json!({"token": token + 1, "ok": true})); + assert!(!tool.waiting(), "another question's answer"); + tool.set_option("missingFontEdit", &json!({"token": token, "ok": true})); + assert!(tool.waiting()); + let acts = tool.poll(&c, false); + assert!(acts.contains(&Action::Exec("select.set".into(), json!({"ids": [other.0]}))), "{acts:?}"); + assert_eq!((tool.editing, tool.caret), (Some(other), 2)); } /// Every new edit of such type asks again, after an earlier OK too, and a style the family lacks diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index d5244aa234..52d455d0d6 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -9471,7 +9471,8 @@ fn double_clicking_type_in_a_missing_font_asks_before_editing() { let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()); let node = |app: &VectorcraftApp| app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap().clone(); let b = node(&app).geometric_bounds().unwrap(); - let at = xf.to_screen(b.center()); + // A quarter of the way in, away from the middle of the text. + let at = xf.to_screen(Point::new(b.x0 + b.width() * 0.25, b.center().y)); let button = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }; let double_click = |app: &mut VectorcraftApp, time: f64| { timed(app, time, vec![egui::Event::PointerMoved(at), button(true), button(false), button(true), button(false)]); @@ -9502,6 +9503,10 @@ fn double_clicking_type_in_a_missing_font_asks_before_editing() { assert_eq!(o["editing"], json!(id)); let caret = o["caret"].as_u64().unwrap(); assert!((1..11).contains(&caret), "caret {caret}"); + // The caret is the one a click at that point puts in the type being edited. + timed(&mut app, 5.0, vec![button(true), button(false)]); + timed(&mut app, 5.1, vec![]); + assert_eq!(app.session.tool_options()["caret"], json!(caret), "the caret where the type was double-clicked"); app.session.tool_text("X", app.view_info()).unwrap(); let NodeKind::Text(t) = &node(&app).kind else { panic!("not text") }; assert_eq!(t.plain_text().find('X'), Some(caret as usize), "{}", t.plain_text());