From 2b05ddfa102de0dbcb5b8d1b0153a9a5cd214046 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 3 Dec 2026 08:09:36 -0800 Subject: [PATCH] Properties: an unfinished Objects on Path Rotate value stays with the groups it was typed for The Rotate field of the Objects on Path Options section kept a typed but unentered value when the selection changed. When the newly selected group had the same Rotate, the field went on showing the old text, and the next Enter applied it to the new group: typing 3+ with one group selected, selecting another group at 0 degrees, then typing 1 and Enter gave the second group 4 degrees. The field now passes NumberField::edit_target the document, its File > Revert count and the selected groups in id order. When any of these changes, the field drops the unfinished value and shows the new groups' Rotate. The same groups selected in another order keep the value. --- .../src/panels/properties/object_sections.rs | 19 +++- crates/ui-egui/src/panels/properties/tests.rs | 101 ++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/panels/properties/object_sections.rs b/crates/ui-egui/src/panels/properties/object_sections.rs index 844305a187..fb00a9a102 100644 --- a/crates/ui-egui/src/panels/properties/object_sections.rs +++ b/crates/ui-egui/src/panels/properties/object_sections.rs @@ -104,10 +104,25 @@ pub(super) fn selected_objects_on_path(app: &VectorcraftApp) -> Option)>; + +/// The [`EditTarget`] of the groups `oop` in the active document. +fn edit_target(app: &VectorcraftApp, oop: &ObjectsOnPathSelection) -> EditTarget { + let st = app.session.active()?; + let mut ids = oop.ids.clone(); + ids.sort_unstable(); + Some((st.uid, st.reverts, ids)) +} + /// The Objects on Path Options of the selected Objects on Path groups: Pivot, the point of each /// object that attaches to the path, and Rotate, the angle each object tilts by from upright on the /// path. A change goes to every selected group in one undo step (`object.objectsOnPath.options`). -/// Where the groups differ, no Pivot square is chosen and Rotate is blank. Detach takes the object +/// Where the groups differ, no Pivot square is chosen and Rotate is blank. A Rotate value typed and +/// not yet entered is dropped when its [`EditTarget`] changes. Detach takes the object /// chosen with its Select/Move widget off the path (`object.objectsOnPath.detach`), and is dimmed /// until one is chosen. pub(super) fn objects_on_path_section(app: &mut VectorcraftApp, ui: &mut Ui, oop: &ObjectsOnPathSelection) { @@ -117,6 +132,7 @@ pub(super) fn objects_on_path_section(app: &mut VectorcraftApp, ui: &mut Ui, oop app.status(e); } }; + let target = edit_target(app, oop); super::section(tl!("Objects on Path Options")).show(ui, |ui, _| { Field::new(tl!("Pivot")).show(ui, |ui, _| { // Mixed while the groups' pivots differ: no square is chosen. @@ -132,6 +148,7 @@ pub(super) fn objects_on_path_section(app: &mut VectorcraftApp, ui: &mut Ui, oop let presets: Vec> = transform::ANGLE_PRESETS.iter().map(|v| Entry::new(NumberPick::Number(*v), format!("{v}°"))).collect(); let out = NumberField::new(tl!("Rotate"), Bind::given(oop.rotate)) + .edit_target(&target) .unit_kind(UnitKind::Degrees) .presets(&presets) .range(-360.0..=f64::INFINITY) diff --git a/crates/ui-egui/src/panels/properties/tests.rs b/crates/ui-egui/src/panels/properties/tests.rs index dea62a6dfa..0cbbca6bc3 100644 --- a/crates/ui-egui/src/panels/properties/tests.rs +++ b/crates/ui-egui/src/panels/properties/tests.rs @@ -1823,6 +1823,107 @@ fn objects_on_path_options_set_pivot_and_rotate_in_one_undo_step() { assert_eq!(undo_depth(&panel.app()), depth + 1, "one undo step for both groups"); } +/// Clicks Rotate, selects its text and types `3+`, leaving the value unfinished. +fn unfinished_rotate(panel: &mut Panel) { + use craft::ui::contract::Role; + panel.click_role("Rotate", Role::SPIN_BUTTON); + panel.key(Key::A, Modifiers::COMMAND); + panel.type_text("3+"); +} + +/// Types `1` into the focused field and presses Enter. +fn finish_with_one(panel: &mut Panel) { + panel.type_text("1"); + panel.key(Key::Enter, Modifiers::NONE); +} + +/// A Rotate value typed for one Objects on Path group and not yet entered stays with that group: +/// with the selection unchanged, `3+` then `1` and Enter gives 4°. After another group with the +/// same Rotate is selected, the field shows that group's value and `1` and Enter gives it 1°. The +/// same groups selected in another order keep the value. +#[test] +fn an_unfinished_rotate_value_does_not_reach_another_group() { + use craft::ui::contract::Role; + let mut app = new_app(); + let a = objects_on_path(&mut app, 150.0, 0.0); + let b = objects_on_path(&mut app, 250.0, 0.0); + app.run("select.set", json!({"ids": [a]})).unwrap(); + let mut panel = Panel::new(app, objects_on_path_options); + let rotates = |panel: &Panel| { + let app = panel.app(); + (pivot_rotate(&app, &a).1, pivot_rotate(&app, &b).1) + }; + unfinished_rotate(&mut panel); + panel.frame(); + finish_with_one(&mut panel); + assert_eq!(rotates(&panel), (4.0, 0.0), "an unchanged target keeps the typed value"); + panel.app().run("object.objectsOnPath.options", json!({"ids": [a], "rotate": 0})).unwrap(); + panel.frame(); + + unfinished_rotate(&mut panel); + panel.app().run("select.set", json!({"ids": [b]})).unwrap(); + panel.frame(); + assert_ne!(panel.value_role("Rotate", Role::SPIN_BUTTON).as_deref(), Some("3+"), "the field drops the value typed for a"); + finish_with_one(&mut panel); + assert_eq!(rotates(&panel), (0.0, 1.0), "b takes 1°, not 3+1"); + + // The same groups selected in another order keep the value typed so far. + panel.app().run("object.objectsOnPath.options", json!({"ids": [b], "rotate": 0})).unwrap(); + panel.app().run("select.set", json!({"ids": [a, b]})).unwrap(); + panel.frame(); + unfinished_rotate(&mut panel); + panel.app().run("select.set", json!({"ids": [b, a]})).unwrap(); + panel.frame(); + finish_with_one(&mut panel); + assert_eq!(rotates(&panel), (4.0, 4.0), "the same groups in another order keep the typed value"); +} + +/// A Rotate value typed and not yet entered is dropped when another document becomes active, even +/// where its group has the same id and Rotate. +#[test] +fn an_unfinished_rotate_value_is_dropped_by_another_document() { + let mut app = new_app(); + let first = objects_on_path(&mut app, 150.0, 0.0); + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + let second = objects_on_path(&mut app, 150.0, 0.0); + assert_eq!(first, second, "both documents' groups have the same id"); + app.run("document.activate", json!({"index": 0})).unwrap(); + let mut panel = Panel::new(app, objects_on_path_options); + let rotate = |panel: &mut Panel, index: u64| { + panel.app().run("document.activate", json!({"index": index})).unwrap(); + pivot_rotate(&panel.app(), &first).1 + }; + + unfinished_rotate(&mut panel); + panel.app().run("document.activate", json!({"index": 1})).unwrap(); + panel.frame(); + finish_with_one(&mut panel); + assert_eq!((rotate(&mut panel, 0), rotate(&mut panel, 1)), (0.0, 1.0), "the other document takes 1°"); +} + +/// A Rotate value typed and not yet entered is dropped when File › Revert replaces the document's +/// content, even where the restored group, selected again, has the same id and Rotate. +#[test] +fn an_unfinished_rotate_value_is_dropped_by_file_revert() { + let mut app = new_app(); + let group = objects_on_path(&mut app, 150.0, 0.0); + let dir = vectorcraft_testkit::TempDir::new("objects-on-path-revert"); + app.services.read = Some(Box::new(|path| std::fs::read(path).map_err(|e| e.to_string()))); + app.services.write = Some(Box::new(|path, bytes| std::fs::write(path, bytes).map_err(|e| e.to_string()))); + app.run("file.saveAs", json!({"path": dir.join("Objects on Path.vectorcraft")})).unwrap(); + // An unsaved change for Revert to undo, leaving the group as saved. + rect(&mut app, 300.0, 20.0, 20.0, 20.0); + app.run("select.set", json!({"ids": [group]})).unwrap(); + let mut panel = Panel::new(app, objects_on_path_options); + unfinished_rotate(&mut panel); + + panel.app().run("file.revert", json!({"confirmed": true})).unwrap(); + panel.app().run("select.set", json!({"ids": [group]})).unwrap(); + panel.frame(); + finish_with_one(&mut panel); + assert_eq!(pivot_rotate(&panel.app(), &group).1, 1.0, "Revert drops the unfinished value"); +} + /// The objects of the Objects on Path group `id`, in their order along the path. fn on_path(app: &VectorcraftApp, id: &Value) -> Vec { let d = &app.session.active().unwrap().doc;