Merge main into feat/script-run

This commit is contained in:
dotCooCoo
2026-11-09 20:30:53 -08:00
64 changed files with 1678 additions and 440 deletions
+23 -16
View File
@@ -183,7 +183,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Lock Guides",
["View", "Guides"],
Some("Cmd+Alt+;"),
"{locked?: bool} toggle (or set) the session's guide lock; locking deselects the ruler guides and guide paths in every open document → {locked}",
"{locked?: bool} toggle (or set) the session's guide lock, leaving the lockGuidesByDefault preference as it is; locking deselects the ruler guides and guide paths in every open document; guide.add and a guide dragged out of a ruler still make new guides while locked → {locked}",
has_doc,
lock_guides
),
@@ -277,6 +277,27 @@ impl Session {
pub fn guides_locked(&self) -> bool {
self.menu.guides_locked
}
/// Set View → Guides → Lock Guides. Locked guides can't stay selected, ruler guides or guide
/// paths, in any open document ([`Session::select`] lets those go in the active one).
pub(crate) fn set_guides_locked(&mut self, locked: bool) {
self.menu.guides_locked = locked;
if !locked {
return;
}
let guides_selected =
self.doc().is_ok_and(|st| !st.selection.guides.is_empty() || st.selection.objects.iter().any(|id| crate::is_guide_path(&st.doc, *id)));
// It fails only without a document, and then no guide is selected.
if guides_selected {
let _ = self.select(|_, sel| sel.guides.clear());
}
let active = self.active;
for (i, st) in self.docs.iter_mut().enumerate() {
if Some(i) != active && crate::deselect_hidden(&self.menu, &st.doc, &mut st.selection) {
st.revision += 1;
}
}
}
}
// ---------- Select ----------
@@ -717,21 +738,7 @@ fn release_guides(s: &mut Session, p: &Value) -> Result<Value> {
fn lock_guides(s: &mut Session, p: &Value) -> Result<Value> {
let v = switch_or(p, "locked", !s.menu.guides_locked, "view.guides.lock")?;
s.menu.guides_locked = v;
// Locked guides can't stay selected, ruler guides or guide paths, in any open document
// ([`Session::select`] lets those go in the active one).
let st = s.doc()?;
if v && (!st.selection.guides.is_empty() || st.selection.objects.iter().any(|id| crate::is_guide_path(&st.doc, *id))) {
s.select(|_, sel| sel.guides.clear())?;
}
if v {
let active = s.active;
for (i, st) in s.docs.iter_mut().enumerate() {
if Some(i) != active && crate::deselect_hidden(&s.menu, &st.doc, &mut st.selection) {
st.revision += 1;
}
}
}
s.set_guides_locked(v);
Ok(json!({ "locked": v }))
}
+16
View File
@@ -285,6 +285,22 @@ fn revolve_on_a_fill_is_checked_in_that_fills_paint() {
assert!(err.contains("simplify the gradient"), "{err}");
}
/// A hidden Revolve still counts as the object's one Revolve: a second one is refused, and the
/// hidden one can be shown again over the geometry effects after it.
#[test]
fn a_second_revolve_is_refused_over_a_hidden_one() {
let (mut s, id) = session_with_rect();
s.execute("effect.apply", &json!({"effect": "threeD.revolve", "ids": [id.0], "item": null})).unwrap();
s.execute("effect.setParams", &json!({"index": 0, "ids": [id.0], "item": null, "visible": false})).unwrap();
s.execute("effect.apply", &json!({"effect": "distort.roughen", "ids": [id.0], "item": null})).unwrap();
let err = s.execute("effect.apply", &json!({"effect": "threeD.revolve", "ids": [id.0], "item": null})).unwrap_err().to_string();
assert!(err.contains("one Revolve effect"), "{err}");
let ids: Vec<_> = node(&s, id).appearance.effects.iter().map(|e| e.id.clone()).collect();
assert_eq!(ids, ["threeD.revolve", "distort.roughen"]);
s.execute("effect.setParams", &json!({"index": 0, "ids": [id.0], "item": null, "visible": true})).unwrap();
assert!(node(&s, id).appearance.effects[0].visible);
}
/// Revolve on a group sweeps every member about one axis on the left edge of their bounds, keeps
/// each member's paint, follows an edited member, expands and undoes as one step.
#[test]
+7
View File
@@ -228,6 +228,7 @@ pub const PREF_SPECS: &[PrefSpec] = &[
// Guides & Grid
p!("guideColor", "Guides & Grid", "Guides", "Color", color),
p!("guideStyle", "Guides & Grid", "Guides", "Style", choice(LINE_STYLE)),
p!("lockGuidesByDefault", "Guides & Grid", "Guides", "Lock Guides by Default", bool),
p!("gridColor", "Guides & Grid", "Grid", "Color", color),
p!("gridStyle", "Guides & Grid", "Grid", "Style", choice(LINE_STYLE)),
p!("gridlineEvery", "Guides & Grid", "Grid", "Gridline every", len(1.0, 16383.0, General)),
@@ -691,10 +692,16 @@ impl Session {
let fonts_folder_changed = p.fonts_folder != self.prefs.fonts_folder;
let hyphen_exceptions_changed = p.hyphenation_exceptions != self.prefs.hyphenation_exceptions;
let corner_radius_changed = p.corner_radius != self.prefs.corner_radius;
let lock_guides_changed = p.lock_guides_by_default != self.prefs.lock_guides_by_default;
if p.trace_presets != self.prefs.trace_presets {
self.trace_preset_changes.replaced();
}
self.prefs = p;
// Guides & Grid › Lock Guides by Default sets the lock when it changes, the saved value at
// start included. Otherwise the lock stays as View › Guides › Lock Guides left it.
if lock_guides_changed {
self.set_guides_locked(self.prefs.lock_guides_by_default);
}
if corner_radius_changed {
// General › Corner Radius is the Rounded Rectangle tool's radius (#394): a tool already
// made (active, or lent a selection tool for a drag) takes the new value.
+3
View File
@@ -116,6 +116,8 @@ pub struct Prefs {
// Guides & Grid
pub guide_color: String,
pub guide_style: String,
/// Lock Guides by Default: the app starts with View › Guides › Lock Guides on.
pub lock_guides_by_default: bool,
pub grid_color: String,
pub grid_style: String,
pub gridline_every: f64,
@@ -424,6 +426,7 @@ impl Default for Prefs {
identify_objects_by: s("objectName"),
guide_color: s("#4affff"),
guide_style: s("lines"),
lock_guides_by_default: false,
grid_color: s("#c8c8c8"),
grid_style: s("lines"),
gridline_every: 72.0,
+34
View File
@@ -3687,6 +3687,40 @@ fn ruler_guides_and_lock() {
assert!(s.execute("guide.remove", &json!({"index": 0})).is_err());
}
/// While guides are locked, a guide dragged out of a ruler and `guide.add` still make new guides,
/// each in one undo step and not selected. The ruler guides and guide paths in the document, the
/// new guides included, can't be selected, moved or deleted.
#[test]
fn new_guides_can_be_made_while_guides_are_locked() {
use vectorcraft_tools::{PointerEvent, PointerKind};
let mut s = session();
let path = guide_path(&mut s, 300.0);
s.execute("guide.add", &json!({"vertical": false, "pos": 50})).unwrap();
s.execute("select.none", &json!({})).unwrap();
s.execute("view.guides.lock", &json!({"locked": true})).unwrap();
let v = ViewInfo { smart_guides: false, ..Default::default() };
let n = undo_len(&s);
s.ruler_guide(true, &PointerEvent::new(PointerKind::Drag, 153.0, 30.0), true, v).unwrap();
s.ruler_guide(true, &PointerEvent::new(PointerKind::Up, 153.0, 30.0), true, v).unwrap();
assert_eq!(guides(&s), [(false, 50.0), (true, 153.0)]);
assert_eq!(undo_len(&s), n + 1);
assert_eq!(s.doc().unwrap().history.undo.last().unwrap().label, "New Guide");
assert_eq!(s.execute("guide.add", &json!({"vertical": true, "pos": 200})).unwrap()["index"], 2);
assert_eq!(guides(&s).len(), 3);
assert_eq!(selected_guides(&s), Vec::<usize>::new());
for (id, params) in [
("guide.select", json!({"indexes": [1]})),
("guide.move", json!({"index": 1, "pos": 170})),
("guide.remove", json!({"index": 1})),
("guide.setLayer", json!({"index": 1, "layer": s.doc().unwrap().current_layer().unwrap().0})),
] {
assert!(matches!(s.execute(id, &params), Err(EngineError::Disabled(..))), "{id}");
}
assert_eq!(guides(&s).len(), 3);
sel(&mut s, &[path]);
assert!(selected(&s).is_empty(), "a guide path can't be selected");
}
#[test]
fn invalid_guide_lock_parameters_keep_guides_selected() {
let mut s = session();
+104
View File
@@ -199,6 +199,110 @@ fn reset_category_and_all() {
assert!(s.execute("prefs.reset", &json!({"category": "Bogus"})).is_err());
}
/// A rectangle made into a guide path; nothing is selected after.
fn guide_path(s: &mut Session, x: f64) -> NodeId {
let id = square(s, x, 0.0);
s.execute("select.set", &json!({"ids": [id.0]})).unwrap();
s.execute("view.guides.make", &json!({})).unwrap();
id
}
/// Lock Guides by Default is off, and preferences saved before it existed leave guides unlocked.
#[test]
fn lock_guides_by_default_is_off_and_older_preferences_leave_guides_unlocked() {
assert!(!Prefs::default().lock_guides_by_default);
let older: Prefs = serde_json::from_value(json!({"keyboardIncrement": 4})).unwrap();
assert!(!older.lock_guides_by_default);
let mut s = Session::new();
s.apply_prefs(older);
assert!(!s.guides_locked());
assert!(s.execute("prefs.set", &json!({"key": "lockGuidesByDefault", "value": "yes"})).is_err());
assert!(!s.guides_locked() && !s.prefs.lock_guides_by_default);
}
/// Preferences saved with the option on start a session with guides locked. A document opened in
/// it has its ruler guides and guide paths locked, and new guides can still be made. View › Guides
/// › Lock Guides then unlocks them for the session and leaves the preference on.
#[test]
fn saved_lock_guides_by_default_locks_a_new_session_and_the_documents_it_opens() {
let file = std::env::temp_dir().join(format!("vc-lock-guides-{}.vectorcraft", std::process::id()));
let file = file.to_string_lossy().to_string();
let mut unlocked = new_doc();
assert!(!unlocked.guides_locked(), "a session without the preference");
let path = guide_path(&mut unlocked, 100.0);
unlocked.execute("guide.add", &json!({"vertical": true, "pos": 50})).unwrap();
unlocked.execute("document.save", &json!({"path": file})).unwrap();
// The preference is set with no document open, as a headless session can.
let mut first = Session::new();
first.execute("prefs.set", &json!({"key": "lockGuidesByDefault", "value": true})).unwrap();
let saved = first.prefs.to_json();
assert_eq!(saved["lockGuidesByDefault"], json!(true));
let mut s = Session::new();
s.apply_prefs(serde_json::from_value(saved).unwrap());
assert!(s.guides_locked());
s.execute("document.open", &json!({"path": file})).unwrap();
let _ = std::fs::remove_file(&file);
assert!(s.guides_locked(), "opening a document keeps the lock");
assert!(matches!(s.execute("guide.select", &json!({"indexes": [0]})), Err(EngineError::Disabled(..))));
s.execute("select.set", &json!({"ids": [path.0]})).unwrap();
assert!(s.doc().unwrap().selection.objects.is_empty(), "a guide path can't be selected");
assert_eq!(s.execute("guide.add", &json!({"vertical": false, "pos": 20})).unwrap()["index"], 1);
assert_eq!(s.execute("view.guides.lock", &json!({})).unwrap(), json!({"locked": false}));
assert!(s.prefs.lock_guides_by_default, "the menu leaves the preference as it is");
s.execute("guide.select", &json!({"indexes": [0]})).unwrap();
s.execute("select.set", &json!({"ids": [path.0]})).unwrap();
assert_eq!(s.doc().unwrap().selection.objects, [path]);
}
/// Changing the preference sets the lock at once and deselects guides in every open document.
/// A change to any other preference, or setting it to the value it has, keeps the session's lock.
#[test]
fn changing_lock_guides_by_default_sets_the_lock_and_other_changes_keep_it() {
let mut s = new_doc();
s.execute("guide.add", &json!({"vertical": true, "pos": 50})).unwrap();
s.execute("guide.select", &json!({"indexes": [0]})).unwrap();
s.execute("file.new", &json!({"width": 400, "height": 400})).unwrap();
let path = guide_path(&mut s, 100.0);
s.execute("select.set", &json!({"ids": [path.0]})).unwrap();
let undo = s.doc().unwrap().history.undo.len();
set_pref(&mut s, "lockGuidesByDefault", json!(true));
assert!(s.guides_locked());
assert!(s.doc().unwrap().selection.objects.is_empty(), "the guide path in the active document");
assert_eq!(s.doc().unwrap().history.undo.len(), undo, "no undo step");
s.execute("document.activate", &json!({"index": 0})).unwrap();
assert!(s.doc().unwrap().selection.guides.is_empty(), "the ruler guide in the other document");
s.execute("view.guides.lock", &json!({"locked": false})).unwrap();
set_pref(&mut s, "keyboardIncrement", json!(4));
set_pref(&mut s, "lockGuidesByDefault", json!(true));
assert!(!s.guides_locked(), "the session's unlock stays");
s.execute("view.guides.lock", &json!({"locked": true})).unwrap();
set_pref(&mut s, "lockGuidesByDefault", json!(false));
assert!(!s.guides_locked(), "turning the preference off unlocks guides");
}
/// Reset turns the option off and unlocks guides. With the option already off, a reset keeps a
/// lock set from the View menu.
#[test]
fn resetting_lock_guides_by_default_unlocks_guides_only_when_it_was_on() {
let mut s = new_doc();
for params in [json!({"category": "Guides & Grid"}), json!({})] {
set_pref(&mut s, "lockGuidesByDefault", json!(true));
assert!(s.guides_locked());
s.execute("prefs.reset", &params).unwrap();
assert!(!s.prefs.lock_guides_by_default, "{params}");
assert!(!s.guides_locked(), "{params}");
}
s.execute("view.guides.lock", &json!({"locked": true})).unwrap();
s.execute("prefs.reset", &json!({})).unwrap();
assert!(s.guides_locked());
}
/// `prefs.set` refuses a recovery or plug-ins folder that is missing or is a file. Nothing changes,
/// other values in the same call included, and the document gets no undo step.
#[test]