diff --git a/crates/engine/src/cmd/retype_installed.rs b/crates/engine/src/cmd/retype_installed.rs index eda6e1105b..a113982379 100644 --- a/crates/engine/src/cmd/retype_installed.rs +++ b/crates/engine/src/cmd/retype_installed.rs @@ -605,8 +605,8 @@ pub(super) fn handed(s: &mut Session) -> Option { impl RetypeRun { /// The search `command` (`type.retype` or `type.retypeFonts`) with params `p` makes in the - /// active document. None when it reads no installed font: `installed` is false, or no shape has - /// a glyph's key. An error where the command fails on its params or on the selection. + /// active document. None when it reads no installed font: `installed` is false, or no shape + /// starts a search ([`starts`]: each is plain or has no glyph's key). An error where the command fails on its params or on the selection. /// The faces to compare are picked when the search runs. pub fn prepare(s: &Session, command: &str, p: &Value) -> Result> { let (command, fonts, tolerance) = match command { @@ -641,9 +641,7 @@ impl RetypeRun { } else { pieces.into_iter().map(|pc| Shape::whole(pc.path)).collect() }; - let sought: Vec = shapes.iter().map(Shape::sought).collect(); - let (keys, near) = keys_of(&sought, tolerance); - if keys.is_empty() && near.is_empty() { + if !shapes.iter().any(|s| starts(&s.sought(), tolerance)) { return Ok(None); } let faces = Faces::Of { doc: st.doc.clone(), fonts }; diff --git a/crates/engine/src/cmd/retype_installed_tests.rs b/crates/engine/src/cmd/retype_installed_tests.rs index 8db2c1ab12..53c7a6bd04 100644 --- a/crates/engine/src/cmd/retype_installed_tests.rs +++ b/crates/engine/src/cmd/retype_installed_tests.rs @@ -353,6 +353,20 @@ fn a_run_away_from_the_command_loads_the_faces_it_finds() { assert!(!run.current(&s)); } +#[test] +fn plain_shapes_alone_start_no_run_away_from_the_command() { + // A rectangle and a bar are plain: the search reads no installed font for them, so the + // command runs at once. + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 600, "height": 400})).unwrap(); + let rect = s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 80, "height": 40})).unwrap()["id"].as_u64().unwrap(); + let bar = s.execute("shape.rectangle", &json!({"x": 10, "y": 100, "width": 4, "height": 60})).unwrap()["id"].as_u64().unwrap(); + s.execute("select.set", &json!({"ids": [rect, bar]})).unwrap(); + for (cmd, p) in [("type.retype", json!({})), ("type.retype", json!({"tolerance": 0.05})), ("type.retypeFonts", json!({}))] { + assert!(super::RetypeRun::prepare(&s, cmd, &p).unwrap().is_none(), "{cmd} {p}"); + } +} + #[test] fn what_a_search_found_is_handed_to_the_next_command_in_its_document() { let mut s = Session::new();