diff --git a/crates/ui-egui/src/panels/glyphs.rs b/crates/ui-egui/src/panels/glyphs.rs index 7c8614d3fc..755983151e 100644 --- a/crates/ui-egui/src/panels/glyphs.rs +++ b/crates/ui-egui/src/panels/glyphs.rs @@ -975,7 +975,7 @@ fn alternates_popup(ui: &mut Ui, face: &vectorcraft_text::FontFace, c: Option face.advance(plain_a), "an alternate wider than the a"); + // The first frame holds "x a" with the plain a, and not with the wider glyph. + let pt = |g: u32| face.advance(g) * 12.0 / face.units_per_em(); + let width = pt(gid('x')) + pt(gid(' ')) + (pt(plain_a) + pt(wide)) / 2.0; + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 900, "height": 300})).unwrap(); + let area = json!({"x": 10, "y": 10, "text": "x a", "size": 12, "area": {"width": width, "height": 16}}); + let a = app.run("text.create", area).unwrap()["id"].as_u64().unwrap(); + let b = app.run("text.thread.add", json!({"from": a, "rect": [200, 10, 150, 60]})).unwrap()["id"].as_u64().unwrap(); + for id in [a, b] { + app.run("text.setRangeStyle", json!({"id": id, "font": alternates_family(true)})).unwrap(); + } + let plain = |app: &VectorcraftApp, id: u64| match &app.session.active().unwrap().doc.node(NodeId(id)).unwrap().kind { + NodeKind::Text(t) => t.plain_text(), + _ => panic!("text"), + }; + assert_eq!((plain(&app, a), plain(&app, b)), ("x a".to_string(), String::new())); + app.run("select.set", json!({"ids": [a]})).unwrap(); + app.session.select_tool("type", Default::default()).unwrap(); + app.session.set_tool_option("textSelection", &json!({"editing": a, "anchor": 2, "caret": 3})); + let ctx = egui::Context::default(); + set_pstate(&ctx, "gl-subset", 1usize); + let undo = app.session.active().unwrap().history.undo.len(); + let popup = open_corner_popup(&ctx, &mut app); + click(&ctx, &mut app, popup[index].center()); + assert_eq!((plain(&app, a), plain(&app, b)), ("x ".to_string(), "a".to_string()), "status: {}", app.ui.status); + assert_eq!(glyph_ids(&app, &json!(b)), [wide]); + assert_eq!(super::super::character::text_editing(&app), Some((NodeId(b), 0, 1)), "the character stays selected"); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo + 1, "one undo step"); + } + /// In Entire Font, a glyph no character maps whose substitutions give other glyphs has the /// corner triangle too: its pop-up lists it and those glyphs, and a pick goes on the selected /// character as a double-click on that glyph's cell would put it.