PhotoCraft: An open-source, photo editor written by scratch in pure Rust
fix(engine): prefs.set and prefs.reset apply the text blending gamma (#987) (#1709)
MarekSpodBiedry088dbba09039
diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rsindex 4b46e8acf..ecef505a7 100644--- a/crates/engine/src/prefs.rs+++ b/crates/engine/src/prefs.rs@@ -1410,6 +1410,8 @@ fn prefs_set(s: &mut Session, p: &Value) -> Result<Value> {return Err(bad(cmd, e));}}+ // `colorSettings.blendTextGamma` lives in the compositor too, as `edit.colorSettings` sets it.+ photocraft_compose::psblend::set_text_gamma(s.color.settings.blend_text_gamma);s.apply_prefs();let view = s.prefs_view();let out: Map<String, Value> = changes.iter().map(|(k, _)| (k.clone(), get_path(&view, k).cloned().unwrap_or(Value::Null))).collect();@@ -1439,6 +1441,7 @@ fn prefs_reset(s: &mut Session, p: &Value) -> Result<Value> {}}s.prefs.edit(|_| ());+ photocraft_compose::psblend::set_text_gamma(s.color.settings.blend_text_gamma);s.apply_prefs();if path.is_some_and(|path| keyed(path).is_some()) {// The removed override is absent, so reading its old path would report an error.diff --git a/crates/engine/tests/text_gamma.rs b/crates/engine/tests/text_gamma.rsindex 4089dcb21..603dbae55 100644--- a/crates/engine/tests/text_gamma.rs+++ b/crates/engine/tests/text_gamma.rs@@ -27,4 +27,21 @@ fn blend_text_gamma_setting() {s.execute("edit.colorSettings", json!({"blendTextGamma": true})).unwrap();assert!((s.color.settings.blend_text_gamma - 1.45).abs() < 1e-6);assert!((photocraft_compose::psblend::text_gamma() - 1.45).abs() < 1e-6);++ // `prefs.set` and `prefs.reset` on `colorSettings` move the compositor's gamma too (#987).+ // Same function, not a second test: tests in one binary run concurrently.+ let in_sync = |s: &Session| (photocraft_compose::psblend::text_gamma() - s.color.settings.blend_text_gamma).abs() < 1e-6;+ s.execute("edit.colorSettings", json!({"blendTextGamma": 1.8})).unwrap();+ s.execute("prefs.set", json!({"path": "colorSettings.blendTextGamma", "value": 1.0})).unwrap();+ assert_eq!(photocraft_compose::psblend::text_gamma(), 1.0);+ assert!(in_sync(&s));+ s.execute("prefs.reset", json!({"path": "colorSettings.blendTextGamma"})).unwrap();+ assert!((photocraft_compose::psblend::text_gamma() - 1.45).abs() < 1e-6);+ assert!(in_sync(&s));+ for reset in [json!({"path": "colorSettings"}), json!({})] {+ s.execute("edit.colorSettings", json!({"blendTextGamma": 1.8})).unwrap();+ s.execute("prefs.reset", reset).unwrap();+ assert!((photocraft_compose::psblend::text_gamma() - 1.45).abs() < 1e-6);+ assert!(in_sync(&s));+ }}