Adjustment layers: name a settings change "Modify <kind> Layer" in History (#17623)

Every `layer.setAdjustment` recorded the History state "Modify
Adjustment", whatever the layer's kind. The reference application names
it after the kind, with the label of the kind's "New ... Layer" state:
"Modify Curves Layer", "Modify Color Balance Layer". The name now comes
from the same `Adjustment::label()`.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
dholzricandClaude Fable 5.2 committed 2026-11-29 11:21:28 -06:00
1 parent a24a1cb7ad
commit 53ebd4234b
3 files changed
+70 -1

No files matched your search

+2
View File
@@ -26,6 +26,8 @@ pub mod actions_cmds;
pub mod actions_edit_cmds;
pub mod adjust_cmds;
mod adjust_params;
#[cfg(test)]
mod adjustment_modify_history_tests;
pub mod analysis_cmds;
pub mod artboard_cmds;
pub mod atn_cmds;
@@ -0,0 +1,61 @@
//! #17623: a change to an adjustment layer's settings is the History state "Modify <kind> Layer",
//! with the label that names the kind's "New <kind> Layer" state, as the reference application
//! records it, instead of "Modify Adjustment" for every kind.
use serde_json::{Value, json};
use crate::Session;
/// The kinds of `layer.newAdjustmentLayer.<kind>`.
const KINDS: [&str; 16] = [
"brightnessContrast",
"levels",
"curves",
"exposure",
"vibrance",
"hueSaturation",
"colorBalance",
"blackWhite",
"photoFilter",
"channelMixer",
"colorLookup",
"invert",
"posterize",
"threshold",
"gradientMap",
"selectiveColor",
];
fn session() -> Session {
let mut s = crate::session();
s.execute("file.new", json!({"width": 16, "height": 16})).unwrap();
s
}
/// Runs `cmd` and returns the one History state it added.
fn step(s: &mut Session, cmd: &str, p: Value) -> String {
let before = s.active().unwrap().history.entries().len();
s.execute(cmd, p).unwrap_or_else(|e| panic!("{cmd}: {e}"));
let mut added = s.active().unwrap().history.entries()[before..].to_vec();
assert_eq!(added.len(), 1, "{cmd}: one History state, got {added:?}");
added.remove(0)
}
#[test]
fn a_change_is_named_after_the_kind_as_its_new_layer_state_is() {
for kind in KINDS {
let mut s = session();
let created = step(&mut s, &format!("layer.newAdjustmentLayer.{kind}"), json!({}));
let label = created.strip_prefix("New ").and_then(|l| l.strip_suffix(" Layer")).unwrap_or_else(|| panic!("{kind}: created as {created:?}"));
// No params resets the layer to its defaults: a change every kind takes.
assert_eq!(step(&mut s, "layer.setAdjustment", json!({})), format!("Modify {label} Layer"), "{kind}");
}
}
#[test]
fn an_eyedropper_change_takes_the_same_name() {
let mut s = session();
step(&mut s, "layer.newAdjustmentLayer.curves", json!({}));
let picked = json!({"eyedropper": {"point": "white", "color": [0.8, 0.8, 0.8]}});
assert_eq!(step(&mut s, "layer.setAdjustment", picked), "Modify Curves Layer");
}
@@ -351,7 +351,13 @@ fn adjustments() -> Vec<CommandSpec> {
|s, p| {
let id = layer_param(s, p)?;
let eyedropped = crate::adjust_params::layer_eyedropper(s, id, p)?;
s.edit("Modify Adjustment", |doc, _| {
// Named after the layer's kind, with the label of its "New … Layer" state (#17623).
let label = match s.active().and_then(|d| d.doc.layer(id)).map(|l| &l.content) {
Some(LayerContent::Adjustment(adj)) => format!("Modify {} Layer", adj.label()),
// Any other layer is refused below, so this name is never recorded.
_ => "Modify Adjustment".to_string(),
};
s.edit(&label, |doc, _| {
let mode = doc.mode;
let l = doc.layer_mut(id).ok_or(EngineError::NoLayer(id))?;
let LayerContent::Adjustment(adj) = &mut l.content else { return Err(EngineError::Other("not an adjustment layer".into())) };