Preferences › Sketch: auto-projection holds across designs (#680) (#959)

Session::replace_design keeps auto_project when file.new, doc.open and doc.recover swap in another design, and the UI keeps it across tabs, adopt and the last-tab close. Regression tests in engine (sketch_project) and ui-egui (documents).
This commit is contained in:
HEOJUNFO authored and GitHub committed 2026-10-13 23:49:51 -04:00
1 parent 4bea4c7785
commit f204042bf2
4 files changed
+68 -6

No files matched your search

+4 -4
View File
@@ -51,7 +51,7 @@ pub static COMMANDS: &[CommandSpec] = &[
fn new_doc(s: &mut Session, p: &Value) -> Result<Value> {
let name = str_(p, "name").unwrap_or("Untitled");
*s = Session::new(Document::new(name));
s.replace_design(Session::new(Document::new(name)));
Ok(json!({"name": name}))
}
@@ -130,7 +130,7 @@ fn open(s: &mut Session, p: &Value) -> Result<Value> {
let mut fresh = Session::new(Document::new(&stem));
let r = if solidcraft_io::is_step_path(path) { add_step(&mut fresh, path, None)? } else { add_mesh(&mut fresh, path, None)? };
fresh.undo.clear();
*s = fresh;
s.replace_design(fresh);
let errors = s.model.results.iter().filter(|r| r.error.is_some()).count();
return Ok(json!({"path": path, "features": s.doc.features.len(), "errors": errors, "bodies": r["bodies"], "warnings": r["warnings"]}));
}
@@ -138,7 +138,7 @@ fn open(s: &mut Session, p: &Value) -> Result<Value> {
if let Some(stem) = default_name_for(&doc.name, path) {
doc.name = stem;
}
*s = Session::new(doc);
s.replace_design(Session::new(doc));
s.path = Some(path.to_string());
let errors = s.model.results.iter().filter(|r| r.error.is_some()).count();
Ok(json!({"path": path, "features": s.doc.features.len(), "errors": errors, "name": s.doc.name}))
@@ -421,7 +421,7 @@ fn recover(s: &mut Session, p: &Value) -> Result<Value> {
if let Some(stem) = entry.path.as_deref().and_then(|path| default_name_for(&doc.name, path)) {
doc.name = stem;
}
*s = Session::new(doc);
s.replace_design(Session::new(doc));
s.path = entry.path.clone();
s.mark_unsaved();
if bool_(p, "discard").unwrap_or(false) {
@@ -148,6 +148,30 @@ fn auto_project_can_be_turned_off() {
assert!(r["projected"].is_null());
}
/// #680: auto-projection is a preference, not part of a design: turning it off holds for the
/// next design started or opened in the session (`doc.recover` replaces the session the same way).
#[test]
fn auto_project_off_holds_for_designs_started_and_opened() {
let dir = std::env::temp_dir().join(format!("solidcraft-auto-project-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
let file = dir.join("box.solidcraft");
let mut s = Session::default();
box_part(&mut s);
run(&mut s, "file.save_as", json!({"path": file.to_string_lossy()}));
run(&mut s, "sketch.auto_project", json!({"value": false}));
run(&mut s, "file.new", json!({}));
assert!(!s.auto_project, "file.new");
run(&mut s, "doc.open", json!({"path": file.to_string_lossy()}));
assert!(!s.auto_project, "doc.open");
let r = run(&mut s, "sketch.create", json!({"plane": {"face": [20, 15, 20]}}));
assert!(r["projected"].is_null(), "{r}");
run(&mut s, "sketch.auto_project", json!({"value": true}));
run(&mut s, "file.new", json!({}));
assert!(s.auto_project, "turned back on, it stays on");
let _ = std::fs::remove_dir_all(&dir);
}
#[test]
fn project_edges_bodies_sketches_and_origin() {
let mut s = Session::default();