mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Live-shape question: bound to the document it was asked in (#12768)
The question stores its document (`__document`, as the Color Picker does) and Yes is refused once another document is active, so the stored path.deleteAnchor parameters never run against another document's layers. Test: yes_after_another_document_became_active_deletes_nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
9a61ea4a66
commit
d79cce14f5
2 files changed
+29
No files matched your search
@@ -32,6 +32,7 @@ fn is_live(app: &PhotocraftApp, r: PathRef) -> bool {
|
||||
/// or "Don't show again" was ticked.
|
||||
pub fn ask(app: &mut PhotocraftApp, r: PathRef, params: &Value) -> bool {
|
||||
let PathRef::Layer(layer) = r else { return false };
|
||||
let Some(document) = app.session.active().map(|st| st.doc.id.0) else { return false };
|
||||
if !is_live(app, r) || dont_show_again::dismissed(app, PREF) {
|
||||
return false;
|
||||
}
|
||||
@@ -43,6 +44,8 @@ pub fn ask(app: &mut PhotocraftApp, r: PathRef, params: &Value) -> bool {
|
||||
f.insert("__command".into(), json!("path.deleteAnchor"));
|
||||
f.insert("__label".into(), json!(tl!("Delete Anchor Point")));
|
||||
f.insert("layer".into(), json!(layer));
|
||||
// The layer id means something only in this document (another may become active meanwhile).
|
||||
f.insert("__document".into(), json!(document));
|
||||
f.insert("params".into(), params.clone());
|
||||
f.insert("__dontShowAgain".into(), json!(PREF));
|
||||
f.insert("skip".into(), json!(false));
|
||||
@@ -59,6 +62,10 @@ pub fn body(ui: &mut egui::Ui, fields: &mut Map<String, Value>) {
|
||||
pub fn confirm(app: &mut PhotocraftApp, fields: &Map<String, Value>) -> Result<Value, String> {
|
||||
let layer = fields.get("layer").and_then(Value::as_u64).ok_or(tl!("No anchor to delete"))?;
|
||||
let params = fields.get("params").cloned().ok_or(tl!("No anchor to delete"))?;
|
||||
let document = fields.get("__document").and_then(Value::as_u64);
|
||||
if document.is_none() || app.session.active().map(|st| st.doc.id.0) != document {
|
||||
return Err(tl!("No anchor to delete").into());
|
||||
}
|
||||
let result = app.run("path.deleteAnchor", params)?;
|
||||
// The anchors shift: a Direct Selection on this path would point at the wrong ones.
|
||||
let r = PathRef::Layer(layer);
|
||||
|
||||
@@ -82,6 +82,28 @@ fn yes_deletes_the_anchor_and_the_layer_is_no_longer_live() {
|
||||
assert_eq!(app.session.active().unwrap().history.undo_label(), Some("Delete Anchor Point"));
|
||||
}
|
||||
|
||||
/// The question belongs to the document it was asked in: Yes after another document became active
|
||||
/// is refused and changes nothing there (layer ids are unique in a session, so this guards the
|
||||
/// binding the way the Color Picker's `__document` does), and the question's own document keeps
|
||||
/// its shape.
|
||||
#[test]
|
||||
fn yes_after_another_document_became_active_deletes_nothing() {
|
||||
let (mut app, shape) = live(Tool::DeleteAnchorPoint);
|
||||
click(&mut app, CORNER);
|
||||
let id = question(&app).expect("the question");
|
||||
let first = app.session.active_index();
|
||||
app.session.execute("file.new", json!({"width": 800, "height": 600})).unwrap();
|
||||
app.sync_views();
|
||||
let other = app.run("shape.create", json!({"kind": "rect", "rect": [450, 100, 200, 150], "fill": "#3070c0"})).unwrap()["layer"].as_u64().unwrap();
|
||||
assert_ne!(app.session.active_index(), first, "the new document is active");
|
||||
let (before, n) = (shape_path(&mut app, other), steps(&app));
|
||||
assert!(crate::dialogs::confirm(&mut app, id).is_err());
|
||||
assert_eq!((shape_path(&mut app, other), steps(&app)), (before, n));
|
||||
assert!(app.session.set_active(first.unwrap()));
|
||||
app.sync_views();
|
||||
assert_eq!(corners(&mut app, shape), 4, "the first document's shape keeps its corner");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_leaves_the_shape_its_parameters_and_history_unchanged() {
|
||||
let (mut app, shape) = live(Tool::DeleteAnchorPoint);
|
||||
|
||||
Reference in new issue
Block a user