From 21c984ed5c797b0126c081d11a3133434e7d106c Mon Sep 17 00:00:00 2001 From: cdwilson127 Date: Wed, 11 Nov 2026 11:17:26 +1300 Subject: [PATCH] INSERT of a drawing file whose block exists no longer asks to redefine it when EXPERT is 2 or more (fixes #2995) EXPERT 2 or more answers the "already exists. Redefine it?" question Yes without asking, so a routine that inserts the same file repeatedly finishes each INSERT. EXPERT below 2 still asks. --- crates/engine/src/cmd/blocks/insert_file.rs | 5 +++-- crates/engine/tests/insert_file.rs | 23 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/blocks/insert_file.rs b/crates/engine/src/cmd/blocks/insert_file.rs index 7a0492fad..667bc12a1 100644 --- a/crates/engine/src/cmd/blocks/insert_file.rs +++ b/crates/engine/src/cmd/blocks/insert_file.rs @@ -29,9 +29,10 @@ pub(super) struct FileRef { } impl FileRef { - /// Whether to ask before redefining: a plain path whose block already exists. + /// Whether to ask before redefining: a plain path whose block already exists. EXPERT 2 or + /// more answers Yes without asking. pub fn ask_redefine(&self, s: &Session) -> bool { - !self.explicit && s.doc().is_ok_and(|d| d.block(&self.name).is_some()) + !self.explicit && s.doc().is_ok_and(|d| d.block(&self.name).is_some() && d.header.i64("EXPERT", 0) < 2) } /// Read the file and (re)define its block. Returns the block's name. diff --git a/crates/engine/tests/insert_file.rs b/crates/engine/tests/insert_file.rs index 23e5d5581..839694000 100644 --- a/crates/engine/tests/insert_file.rs +++ b/crates/engine/tests/insert_file.rs @@ -150,6 +150,29 @@ fn a_drawing_file_becomes_a_block_with_its_insbase_and_tables() { assert_eq!(inserts(&s).len(), n); } +#[test] +fn expert_two_or_more_redefines_a_file_block_without_asking() { + // #2995: with EXPERT 2 or more the "already exists. Redefine it?" question is not asked; it + // is answered Yes, so the next INSERT of the same file finishes and the block is redefined + // from the file as it is now. + hooks(); + let dir = TempDir::new("insert-file-expert"); + let bolt = dir.file("bolt.dxf", "10,10"); + let mut s = Session::new(); + s.script(&format!("-INSERT {bolt} 0,0 1 1 0\n")).unwrap(); + s.execute("setvar", &json!({ "name": "EXPERT", "value": 2 })).unwrap(); + dir.file("bolt.dxf", "0,0"); + s.script(&format!("-INSERT {bolt} 20,0 1 1 0\n")).unwrap(); + assert!(s.running.is_none(), "INSERT finished: {}", s.prompt_text()); + assert_eq!(inserts(&s).len(), 2); + assert_eq!(s.doc().unwrap().block("bolt").unwrap().base, Vec3::ZERO, "redefined from the file"); + + // EXPERT 1 still asks. + s.execute("setvar", &json!({ "name": "EXPERT", "value": 1 })).unwrap(); + s.cmdline(&format!("-INSERT {bolt}")).unwrap(); + assert!(s.prompt_text().contains("Redefine"), "{}", s.prompt_text()); +} + #[test] fn exploded_json_insert_is_one_undo_step() { for params in [json!({ "name": "*B", "at": [5, 5] }), json!({ "name": "B", "at": [5, 5], "explode": true })] {