diff --git a/crates/ui-egui/src/dialogs/warichu.rs b/crates/ui-egui/src/dialogs/warichu.rs
index cbce874539..123d52f407 100644
--- a/crates/ui-egui/src/dialogs/warichu.rs
+++ b/crates/ui-egui/src/dialogs/warichu.rs
@@ -68,6 +68,7 @@ fn rows(lengths: LengthUnits) -> Vec {
/// Open Warichu Settings on the characters the Character panel acts on.
pub fn open(app: &mut VectorcraftApp) -> Result {
crate::panels::character::text_style(app).ok_or("select some type first")?;
+ let document = app.session.active().ok_or("no document")?.uid;
let shared = crate::panels::character::shared_warichu(app);
let mut fields = DialogFields::new();
set_shared(&mut fields, KEYS[0], shared.lines.map(i64::from));
@@ -83,6 +84,9 @@ pub fn open(app: &mut VectorcraftApp) -> Result {
if p.is_empty() {
return Ok(());
}
+ if !app.session.active().is_some_and(|active| active.uid == document) {
+ return Err(tl!("Warichu Settings can only change the document where it was opened.").to_owned());
+ }
crate::panels::character::run_format(app, Value::Object(p)).map(|_| ())
})
.ok_or("no window")?;
@@ -260,6 +264,42 @@ mod tests {
assert_eq!(params(&fields, &initial).get("warichuGap"), Some(&json!(MAX_WARICHU_GAP)));
}
+ #[test]
+ fn warichu_settings_refuses_confirmation_in_another_drawing() {
+ use craft::ui::dialog::{HeldOk, dialog_id};
+
+ let (mut app, source_id) = app();
+ let source_before = settings(&app, source_id);
+ let source_undo = app.session.active().unwrap().history.undo.len();
+ app.run("ui.warichuSettings", json!({})).unwrap();
+ driver::set(&mut app, "warichuLines", json!(4));
+ let ctx = app.ui_ctx.clone().unwrap();
+ let host = app.dialogs().unwrap();
+ let id = dialog_id(KIND);
+ assert!(!host.with(|h| h.confirm_by_id(&ctx, id)), "the edit waits for the app");
+
+ app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
+ let target_id = app.run("text.create", json!({"x": 10, "y": 50, "text": "other"})).unwrap()["id"].as_u64().unwrap();
+ app.run("select.set", json!({"ids": [target_id]})).unwrap();
+ let target_before = settings(&app, target_id);
+ let target_undo = app.session.active().unwrap().history.undo.len();
+ driver::pump(&mut app);
+ assert_eq!(
+ (settings(&app, target_id), app.session.active().unwrap().history.undo.len()),
+ (target_before, target_undo),
+ "the other drawing's text and undo history stay untouched"
+ );
+ assert!(matches!(host.with(|h| h.held_state(id)), Some(HeldOk::Refused(_))));
+ assert_eq!(driver::fields(&app).number("warichuLines"), Some(4.0));
+
+ app.run("document.activate", json!({"index": 0})).unwrap();
+ app.run("select.set", json!({"ids": [source_id]})).unwrap();
+ assert_eq!(settings(&app, source_id), source_before);
+ assert!(crate::dialogs::tests::confirm(&mut app), "confirm the retained edit on its original drawing");
+ assert_eq!(settings(&app, source_id), [(false, 4, 0.0, 50.0, WarichuAlign::Auto)]);
+ assert_eq!(app.session.active().unwrap().history.undo.len(), source_undo + 1);
+ }
+
/// While the Type tool edits text, OK sets the selected characters.
#[test]
fn warichu_settings_dialog_sets_the_range_the_type_tool_selects() {