mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Retype: plain shapes alone run the command at once
A selection of plain shapes (rectangles, bars) no longer starts a background search of the installed fonts, which would read no font for them. The command runs at once, as it does with `installed` false.
This commit is contained in:
1 parent
6a71ec9638
commit
1285de28ef
2 files changed
+17
-5
No files matched your search
@@ -605,8 +605,8 @@ pub(super) fn handed(s: &mut Session) -> Option<Installed> {
|
||||
|
||||
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<Option<RetypeRun>> {
|
||||
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<Sought> = 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 };
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user