Links: Placement Options does not edit an image placed after Undo

Placement Options checked the document and its reverts before OK, but not
Undo or Redo. After undoing the place of the image it opened on, a new
image can take the same id, and OK then changed that image's Placement
Options. OK now refuses after an Undo or Redo in the opening document, as
Create Object Mosaic does, and asks to reopen the dialog.

The guard was missing since the dialog started applying to the images it
opened on (62199b98b3).
This commit is contained in:
dotCooCoo committed 2026-12-02 01:37:45 -08:00
1 parent 7554b7fc30
commit 628d21f37c
5 files changed
+42 -5

No files matched your search

+1 -1
View File
@@ -1768,7 +1768,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"ui.placementOptionsDialog",
"Placement Options…",
"",
"{ids?} open Placement Options for images `ids` (default: the selected ones; dialog `placementOptions`: ids, preserve, align, clip, see links.placementOptions); OK runs links.placementOptions",
"{ids?} open Placement Options for images `ids` (default: the selected ones; dialog `placementOptions`: ids, preserve, align, clip, see links.placementOptions); OK runs links.placementOptions in the document it opened in, and refuses after that document is reverted or after an Undo or Redo there (reopen the dialog)",
),
(
"ui.relinkDialog",
@@ -45,7 +45,7 @@ fn params() -> Vec<Param> {
/// Open the dialog on the placement options of images `ids` (default: the selected ones).
pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
let active = app.session.active().ok_or("no document open")?;
let source = (active.uid, active.reverts);
let source = (active.uid, active.reverts, active.history_restores);
let ids = p.get("ids").cloned().unwrap_or(Value::Null);
let r = app.session.execute(CMD, &json!({ "ids": ids })).map_err(|e| e.to_string())?;
// The images read: OK applies to these, whatever is selected by then.
@@ -57,7 +57,7 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
("align", FieldValue::Int(align as i64)),
("clip", FieldValue::Bool(placement["clip"].as_bool().unwrap_or(false))),
]);
fields.set(OPENING, FieldValue::Json(json!({"uid": source.0, "reverts": source.1, "ids": ids})));
fields.set(OPENING, FieldValue::Json(json!({"uid": source.0, "reverts": source.1, "historyRestores": source.2, "ids": ids})));
let ctx = app.ui_ctx.clone().ok_or("no window")?;
let dialog = HostedParamDialog::new(&ctx, KEY, fields, |fields| {
ParamDialog::new(KEY, tl!("Placement Options"), params())
@@ -74,6 +74,9 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
if Some(active.reverts) != opening["reverts"].as_u64() {
return Err(tl!("The document was reverted. Reopen this dialog to continue.").to_owned());
}
if Some(active.history_restores) != opening["historyRestores"].as_u64() {
return Err(tl!("Reopen Placement Options after Undo or Redo.").to_owned());
}
let align = f.int("align").and_then(|i| usize::try_from(i).ok()).and_then(|i| ALIGN.get(i).copied()).unwrap_or(ALIGN[CENTRE]);
let params = json!({ "ids": opening["ids"], "preserve": f.text("preserve"), "align": align, "clip": f.bool("clip").unwrap_or(false) });
app.run(CMD, params).map(|_| ())
@@ -170,4 +173,35 @@ mod tests {
crate::tests::picks::answer_dialog(&mut app, dialog, &[("preserve", json!("fit"))], true);
assert_eq!(placement(&mut app)["preserve"], "fit");
}
#[test]
fn held_placement_options_do_not_edit_an_image_placed_after_undo() {
let dir = vectorcraft_testkit::TempDir::new("placement-options-undo");
let path = dir.join("linked.png");
let image = Image::from_raw(2, 2, ChannelLayout::Rgba, SampleType::U8, vec![255; 16]).unwrap();
std::fs::write(&path, craft_image_codecs::encode(&image, Format::Png, &EncodeOptions::default()).unwrap()).unwrap();
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
let place = |app: &mut VectorcraftApp| {
app.run("file.place", json!({"path": path, "at": [100, 100], "link": true})).unwrap()["ids"][0].as_u64().unwrap()
};
let link = place(&mut app);
let placement = |app: &mut VectorcraftApp| app.run(CMD, json!({"ids": [link]})).unwrap()["placement"].clone();
open(&mut app, &json!({"ids": [link]})).unwrap();
let ctx = app.ui_ctx.clone().unwrap();
let dialog = dialog_id(KEY);
let host = app.dialogs().unwrap();
host.with(|h| {
h.set_json_field(&ctx, dialog, "preserve", json!("fit")).unwrap();
assert!(!h.confirm_by_id(&ctx, dialog));
});
app.run("edit.undo", json!({})).unwrap();
assert_eq!(place(&mut app), link, "the replacement image takes the undone image's id");
let original = placement(&mut app);
let undo = app.session.active().unwrap().history.undo.len();
crate::dialogs::host::pump(&mut app, &ctx);
assert_eq!(placement(&mut app), original, "the replacement image keeps its Placement Options");
assert_eq!(app.session.active().unwrap().history.undo.len(), undo);
assert!(matches!(host.with(|h| h.held_state(dialog)), Some(HeldOk::Refused(_))));
}
}
+1 -1
View File
@@ -1769,7 +1769,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"ui.placementOptionsDialog",
"Placement Options…",
"",
"{ids?} open Placement Options for images `ids` (default: the selected ones; dialog `placementOptions`: ids, preserve, align, clip, see links.placementOptions); OK runs links.placementOptions",
"{ids?} open Placement Options for images `ids` (default: the selected ones; dialog `placementOptions`: ids, preserve, align, clip, see links.placementOptions); OK runs links.placementOptions in the document it opened in, and refuses after that document is reverted or after an Undo or Redo there (reopen the dialog)",
),
(
"ui.relinkDialog",
+2 -1
View File
@@ -884,7 +884,8 @@ art too large at that scale) keeps the dialog open.
Placement Options: the Links panel's flyout (or `ui.placementOptionsDialog {ids?}` for agents) opens the
`placementOptions` dialog for the selected images (fields `ids`, `preserve`: `transforms`/`bounds`/`fileDimensions`/
`fit`/`fill`, `align`: `topLeft` … `bottomRight`, `clip`). `ui.dialog.confirm` runs `links.placementOptions` with them as
one undo step, on the images the dialog opened on even when the selection has changed since.
one undo step, on the images the dialog opened on even when the selection has changed since. After that document is
reverted, or after an Undo or Redo in it, the confirm is refused and the dialog stays open; reopen it to continue.
Relink: the Links panel's Relink… button and flyout item (or `ui.relinkDialog {ids?}` for agents) open the `relink`
dialog for the selected images and placed documents (fields `ids`, `links`: `[{name, ids}]`, one row per linked file,
+2
View File
@@ -13921,6 +13921,8 @@ that document is active. Confirming after a document switch closes the dialog wi
Canceling or replacing that dialog does not cancel an interaction in another document. A supplied `__doc` must be
an unsigned integer; omitting it preserves the command dialog's existing behavior.
MCP clients must reopen Placement Options before confirming again after Undo, Redo, or a revert in the document where it opened.
## Justification options