mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge #17975 into the merge queue batch
Adjustment layers: name a settings change "Modify <kind> Layer" in History (#17623)
This commit is contained in:
commit
e0aa5defc3
3 files changed
+70
-1
No files matched your search
@@ -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;
|
||||
#[cfg(test)]
|
||||
mod arrange_history_names_tests;
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
@@ -363,7 +363,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())) };
|
||||
|
||||
Reference in new issue
Block a user