mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Actions: an empty Content-Aware Fill step after a Custom fill stops and says why (#14254)
The workspace remembers Custom sampling but not its painted area (Custom reopens empty), so an empty recorded step had no area to sample and failed with the command's parameter error. It now stops before filling with a message that says the Custom area isn't remembered and how to go on, and never falls back to another sampling area. The document and the remembered settings are unchanged.
This commit is contained in:
1 parent
1ce53d5942
commit
9e8827aa45
4 files changed
+45
-9
No files matched your search
@@ -159,7 +159,7 @@ pub fn playback_params(s: &Session, id: &str, p: &Value) -> Result<Value> {
|
||||
object.remove("__atnCustom");
|
||||
}
|
||||
if id == "edit.contentAwareFill" {
|
||||
crate::atn_cmds::caf_remembered(&mut p, s.prefs());
|
||||
crate::atn_cmds::caf_remembered(&mut p, s.prefs())?;
|
||||
}
|
||||
if id == "layer.setProps"
|
||||
&& let Some(target) = p.get("_actionLayer")
|
||||
|
||||
@@ -3,6 +3,7 @@ use super::descriptors::{desc, enm, jstr};
|
||||
use super::fields::{Mapped, step};
|
||||
use super::tables::lookup_back;
|
||||
use super::{D, Descriptor, Map, Value};
|
||||
use crate::EngineError;
|
||||
|
||||
const CMD: &str = "edit.contentAwareFill";
|
||||
const SOURCE: &str = "_atnCafDescriptor";
|
||||
@@ -99,10 +100,12 @@ fn descriptor(p: &Value) -> Option<Descriptor> {
|
||||
|
||||
/// Resolve an empty recorded step: the remembered settings fill what the step doesn't name, and
|
||||
/// before any were remembered it writes to a new layer. Playing never changes what is remembered.
|
||||
pub(crate) fn caf_remembered(p: &mut Value, prefs: &crate::prefs::Preferences) {
|
||||
let Some(object) = p.as_object_mut() else { return };
|
||||
/// Remembered Custom sampling is refused: its area is painted in the workspace, which keeps none
|
||||
/// (Custom reopens empty), and the step must not sample another area instead.
|
||||
pub(crate) fn caf_remembered(p: &mut Value, prefs: &crate::prefs::Preferences) -> Result<(), EngineError> {
|
||||
let Some(object) = p.as_object_mut() else { return Ok(()) };
|
||||
if object.remove(REMEMBERED).and_then(|v| v.as_bool()) != Some(true) {
|
||||
return;
|
||||
return Ok(());
|
||||
}
|
||||
let saved = prefs.dialogs.get(CAF_WORKSPACE_PREFS);
|
||||
for (param, flag) in PARAMS.iter().map(|param| (*param, matches!(*param, "sampleAllLayers" | "scale" | "mirror"))) {
|
||||
@@ -113,6 +116,11 @@ pub(crate) fn caf_remembered(p: &mut Value, prefs: &crate::prefs::Preferences) {
|
||||
}
|
||||
}
|
||||
object.entry("output").or_insert_with(|| "new".into());
|
||||
if object.get("sampling").and_then(Value::as_str) == Some("custom") && !["area", "channel", "samplingStrokes"].iter().any(|key| object.contains_key(*key)) {
|
||||
let msg = "this step plays with the remembered settings, and their Custom sampling area isn't remembered: fill once with Auto or Rectangular sampling in Content-Aware Fill, then play it again";
|
||||
return Err(EngineError::BadParams { cmd: CMD.into(), msg: msg.into() });
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Import the verified seven-field form, retaining noncanonical wire data for an unchanged save.
|
||||
|
||||
@@ -376,6 +376,27 @@ fn settings_closed_without_a_fill_are_not_carried_forward() {
|
||||
assert_eq!(play_empty_recorded_step(&mut restarted), 1, "New Layer: no fill has run");
|
||||
}
|
||||
|
||||
/// After a confirmed Custom fill an empty recorded step stops and says why, instead of filling from another area: the
|
||||
/// workspace remembers Custom but not its painted area (Custom reopens empty), so the step has none (#14254).
|
||||
#[test]
|
||||
fn an_empty_recorded_step_after_a_custom_fill_stops_and_says_why() {
|
||||
let mut app = app_with_selection();
|
||||
open(&mut app).unwrap();
|
||||
ui(&mut app, json!({"sampling": "custom", "output": "current"})).unwrap();
|
||||
ui(&mut app, json!({"stroke": {"points": [[20.0, 120.0], [60.0, 120.0]], "size": 8}})).unwrap();
|
||||
ui(&mut app, json!({"commit": true})).unwrap();
|
||||
close_all(&mut app);
|
||||
let remembered = app.session.prefs().dialogs.get(photocraft_engine::atn_cmds::CAF_WORKSPACE_PREFS).cloned().unwrap();
|
||||
assert_eq!(remembered["sampling"], "custom", "the confirmed fill remembers Custom: {remembered}");
|
||||
let revision = app.session.active().unwrap().revision;
|
||||
let result = play_empty_step(&mut app);
|
||||
assert_eq!(result["ran"], 0, "{result}");
|
||||
let error = result["failed"]["error"].as_str().unwrap_or_default();
|
||||
assert!(error.contains("Custom sampling area isn't remembered"), "{result}");
|
||||
assert_eq!(app.session.active().unwrap().revision, revision, "the document is unchanged");
|
||||
assert_eq!(app.session.prefs().dialogs.get(photocraft_engine::atn_cmds::CAF_WORKSPACE_PREFS), Some(&remembered), "playing remembers nothing");
|
||||
}
|
||||
|
||||
/// A new app over the saved preferences `prefs`, moved as startup does.
|
||||
fn restart(prefs: photocraft_engine::prefs::Preferences) -> Box<PhotocraftApp> {
|
||||
let mut restarted = app_with_selection();
|
||||
@@ -386,6 +407,14 @@ fn restart(prefs: photocraft_engine::prefs::Preferences) -> Box<PhotocraftApp> {
|
||||
|
||||
/// Plays an action of one empty recorded Content-Aware Fill step and returns how many layers it added.
|
||||
fn play_empty_recorded_step(app: &mut PhotocraftApp) -> usize {
|
||||
let layers = app.session.active().unwrap().doc.layers.len();
|
||||
let result = play_empty_step(app);
|
||||
assert_eq!(result["ran"], 1, "{result}");
|
||||
app.session.active().unwrap().doc.layers.len() - layers
|
||||
}
|
||||
|
||||
/// Plays an action of one empty recorded Content-Aware Fill step and returns what `actions.play` answers.
|
||||
fn play_empty_step(app: &mut PhotocraftApp) -> Value {
|
||||
use craft_psd::atn::{AtnAction, AtnEvent, AtnFile, AtnItem};
|
||||
use craft_psd::descriptor::{Descriptor, UnicodeString};
|
||||
let item = AtnItem {
|
||||
@@ -401,10 +430,7 @@ fn play_empty_recorded_step(app: &mut PhotocraftApp) -> usize {
|
||||
};
|
||||
let imported = photocraft_engine::atn_cmds::import(&craft_psd::atn::write(&file).unwrap()).unwrap();
|
||||
app.session.actions_mut().list.push(imported.actions.into_iter().next().unwrap()).unwrap();
|
||||
let layers = app.session.active().unwrap().doc.layers.len();
|
||||
let result = app.session.execute("actions.play", json!({"action": 0})).unwrap();
|
||||
assert_eq!(result["ran"], 1, "{result}");
|
||||
app.session.active().unwrap().doc.layers.len() - layers
|
||||
app.session.execute("actions.play", json!({"action": 0})).unwrap()
|
||||
}
|
||||
|
||||
/// The engine's sampling area over the plan's rectangle (what the fill samples) and its fill area.
|
||||
|
||||
+3
-1
@@ -430,7 +430,9 @@ step with dialogs on (#14254); the enumeration type IDs are explicit in
|
||||
An empty descriptor (no keys) plays with the settings the fill workspace remembers
|
||||
(`prefs.dialogs["edit.contentAwareFill.workspace"]`), New Layer before any are remembered; it
|
||||
imports as `{"_atnCafRemembered": true}`, which `playback_params` resolves, and saves back
|
||||
empty. Playing a step never changes what is remembered.
|
||||
empty. Playing a step never changes what is remembered. When the remembered sampling is Custom,
|
||||
the step stops with a message instead of filling: the workspace doesn't remember the painted
|
||||
Custom area (Custom reopens empty), and the step must not sample another area instead.
|
||||
|
||||
Descriptor types, source identity and key order survive save while its native settings are
|
||||
unchanged. Editing a supported setting exports the new values in canonical form instead of
|
||||
|
||||
Reference in new issue
Block a user