PhotoCraft: An open-source, photo editor written by scratch in pure Rust
fix(gradient): respect Lock All on Gradient Fills (#3093) (#3120)
Sir Starcha893113502cd
diff --git a/crates/engine/src/gradient_fill_cmds.rs b/crates/engine/src/gradient_fill_cmds.rsindex 24b0905cd..ac6005e66 100644--- a/crates/engine/src/gradient_fill_cmds.rs+++ b/crates/engine/src/gradient_fill_cmds.rs@@ -17,7 +17,7 @@ use photocraft_doc::{Document, Fill, GradientStyle, Layer, LayerContent, LayerIduse photocraft_geom::Rect;use serde_json::{Value, json};-use crate::commands::{CommandSpec, blend_from_str, layer_param};+use crate::commands::{CommandSpec, blend_from_str, check_pixels_unlocked, layer_param};use crate::presets::gradients::{GradientPreset, transparency_param};use crate::{EngineError, Result, Session};@@ -341,6 +341,10 @@ fn set(s: &mut Session, p: &Value) -> Result<Value> {}fn replace_fill(s: &mut Session, id: LayerId, label: &str, new: Fill) -> Result<()> {+ {+ let doc = &s.active().ok_or(EngineError::NoDocument)?.doc;+ check_pixels_unlocked(doc, id)?;+ }s.edit(label, |doc, _| {let mode = doc.mode;let l = doc.layer_mut(id).ok_or(EngineError::NoLayer(id))?;diff --git a/crates/engine/src/gradient_fill_cmds/tests.rs b/crates/engine/src/gradient_fill_cmds/tests.rsindex 4d16838d3..bb357df05 100644--- a/crates/engine/src/gradient_fill_cmds/tests.rs+++ b/crates/engine/src/gradient_fill_cmds/tests.rs@@ -159,6 +159,32 @@ fn set_moves_handles_and_restyles_in_one_undo_step() {assert_eq!(s.active().unwrap().history.past_len(), h);}+#[test]+fn locked_gradient_fill_rejects_content_edits_without_history() {+ let mut s = session(8, "white");+ s.execute(CREATE, json!({"from": [0, 0], "to": [16, 0], "stops": [[0, "#000000"], [1, "#ffffff"]], "dither": false})).unwrap();+ s.execute("layer.lockLayers", json!({"all": true})).unwrap();+ let original = active_fill(&s);+ let locked_history = s.active().unwrap().history.past_len();++ for (command, params) in [(SET, json!({"reverse": true})), (STOP, json!({"action": "color", "index": 0, "color": "#ff0000"}))] {+ let result = s.execute(command, params.clone());+ assert!(matches!(&result, Err(EngineError::Other(message)) if message.contains("locked")), "{command} {params}: {result:?}");+ assert_eq!(active_fill(&s), original, "{command} changed the fill");+ assert_eq!(s.active().unwrap().history.past_len(), locked_history, "{command} added history");+ }++ s.execute("layer.lockLayers", json!({"all": false})).unwrap();+ for (command, params) in [(SET, json!({"reverse": true})), (STOP, json!({"action": "color", "index": 0, "color": "#ff0000"}))] {+ let history = s.active().unwrap().history.past_len();+ s.execute(command, params).unwrap();+ assert_eq!(s.active().unwrap().history.past_len(), history + 1, "{command} records one step");+ s.execute("edit.undo", json!({})).unwrap();+ assert_eq!(active_fill(&s), original, "undo restores the fill after {command}");+ assert_eq!(s.active().unwrap().history.past_len(), history);+ }+}+#[test]fn stops_add_move_recolour_delete_and_midpoints() {let mut s = session(8, "white");