Merge #18415 into the merge queue batch

Smart Objects: name the Reset Transform History state "Reset Transforms" (#18285)
This commit is contained in:
David Mann committed 2026-12-01 01:20:34 +01:00
commit dcd316c592
2 files changed
+52 -1

No files matched your search

@@ -103,7 +103,8 @@ pub(super) fn reset_transform(s: &mut Session, p: &Value) -> Result<Value> {
if ![dx, dy, cx, cy].iter().all(|v| v.is_finite()) || !rel.0.iter().all(|v| v.is_finite()) {
return Err(other("the smart object's placement is not a usable transform"));
}
s.edit("Reset Transform", |doc, _| {
// The History state is plural, the entry is not (#18285).
s.edit("Reset Transforms", |doc, _| {
// The Warp is part of what the reference takes back, so the re-render below starts from the
// unwarped contents. How far a painted Smart Filter mask should follow a cleared warp is
// unmeasured: here it follows the placement, as it does under Free Transform.
@@ -342,3 +343,7 @@ pub(super) fn via_copy(s: &mut Session, p: &Value) -> Result<Value> {
Ok(json!({"layer": new_id.0}))
})
}
#[cfg(test)]
#[path = "reset_transform_history_name_tests.rs"]
mod reset_transform_history_name_tests;
@@ -0,0 +1,46 @@
//! #18285: Layer › Smart Objects › Reset Transform records its History state as "Reset Transforms", as the reference
//! application does. The entry itself keeps its name, "Reset Transform".
use photocraft_geom::Rect;
use serde_json::json;
use crate::Session;
const RESET: &str = "layer.smartObjects.resetTransform";
/// A document whose active layer is a smart object, scaled to 50 % / 30 % and rotated 30°.
fn transformed_smart_object() -> Session {
let mut s = crate::session();
s.execute("file.new", json!({"width": 64, "height": 48})).unwrap();
s.execute("layer.new.layer", json!({})).unwrap();
s.edit("paint", |doc, active| {
doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap().fill_rect(Rect::new(10, 8, 40, 30), &[1.0, 0.0, 0.0, 1.0]);
Ok(())
})
.unwrap();
let id = s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap()["layer"].as_u64().unwrap();
s.execute("edit.transform", json!({"layer": id, "scaleX": 50, "scaleY": 30, "rotate": 30})).unwrap();
s
}
/// How many History states there are, and the name of the newest.
fn history(s: &Session) -> (usize, Option<String>) {
let history = &s.active().unwrap().history;
(history.past_len(), history.undo_label().map(String::from))
}
#[test]
fn reset_transform_adds_one_history_state_named_reset_transforms() {
let mut s = transformed_smart_object();
let states = history(&s).0;
s.execute(RESET, json!({})).unwrap();
assert_eq!(history(&s), (states + 1, Some("Reset Transforms".to_string())));
}
/// Only the History name is plural: the menus still show the entry as "Reset Transform".
#[test]
fn the_entry_keeps_its_name() {
// A session installs the commands.
let _session = crate::session();
assert_eq!(crate::commands::find(RESET).unwrap().label, "Reset Transform");
}