From 628d21f37cef99ce58d2d5215a727768d97d9ce9 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 2 Dec 2026 01:37:45 -0800 Subject: [PATCH] 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 (62199b98b3d). --- crates/mcp/src/ui_catalog.rs | 2 +- .../ui-egui/src/dialogs/placement_options.rs | 38 ++++++++++++++++++- crates/ui-egui/src/menus/ui_commands.rs | 2 +- docs/control-protocol.md | 3 +- docs/mcp.md | 2 + 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index 6852f317b3..b344c82d0c 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -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", diff --git a/crates/ui-egui/src/dialogs/placement_options.rs b/crates/ui-egui/src/dialogs/placement_options.rs index 03b4cc19bd..3dc00a9bfb 100644 --- a/crates/ui-egui/src/dialogs/placement_options.rs +++ b/crates/ui-egui/src/dialogs/placement_options.rs @@ -45,7 +45,7 @@ fn params() -> Vec { /// Open the dialog on the placement options of images `ids` (default: the selected ones). pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result { 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 { ("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 { 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(_)))); + } } diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index b4cf91497d..d8e820861d 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -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", diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 21c81bda1e..c5490df20f 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -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, diff --git a/docs/mcp.md b/docs/mcp.md index ccbe5eb0e8..304da3b487 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -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