fix(puppet-warp): drop open Puppet Warp and other distort sessions when the active document changes (#5092) (#5123)

This commit is contained in:
MarekSpodBiedry authored and GitHub committed 2026-10-14 13:07:55 -04:00
1 parent a076f617e0
commit 94fdd279e8
3 files changed
+54

No files matched your search

+1
View File
@@ -1959,6 +1959,7 @@ pub(crate) fn retain_gpu_documents(app: &mut PhotocraftApp) {
/// Tabs + canvas for the active document, or the start screen; then drops layers dragged onto
/// another document (`layer_transfer`).
pub fn document_area(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
crate::distort_ui::drop_foreign(app);
documents(app, ui);
crate::layer_transfer::finish(app, ui.ctx());
// Once a frame, not per document view: the right-click or options-bar Brush Preset picker.
+21
View File
@@ -27,6 +27,8 @@ pub struct Distort {
pub vanishing: Option<crate::vp_ui::VpSession>,
/// Filter Gallery dialog (gallery_ui).
pub gallery: Option<crate::gallery_ui::GalleryDialog>,
/// The document the open sessions belong to, noted by [`drop_foreign`] on the first frame they are open.
owner: Option<photocraft_doc::DocId>,
}
impl Distort {
@@ -236,8 +238,27 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) -> bool {
false
}
/// Drops the open sessions once the active document is not the one they were started on (closed, or another one
/// opened or switched to). Without this, Puppet Warp's preview of the old document replaced the new document's canvas (#5092).
pub fn drop_foreign(app: &mut PhotocraftApp) {
let current = app.session.active().map(|s| s.doc.id);
if !app.distort.active() && app.distort.gallery.is_none() {
app.distort.owner = None;
} else if app.distort.owner.is_none() {
app.distort.owner = current;
} else if app.distort.owner != current {
app.distort.liquify = None;
app.distort.puppet = None;
app.distort.perspective = None;
app.distort.vanishing = None;
app.distort.gallery = None;
app.distort.owner = None;
}
}
/// Full-window dialogs (Liquify, Filter Gallery).
pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {
drop_foreign(app);
if app.distort.gallery.is_some() {
crate::gallery_ui::show(app, ctx);
}
+32
View File
@@ -454,6 +454,38 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
mod tests {
use super::*;
/// #5092: a Puppet Warp session left open does not follow the user to a new document.
#[test]
fn session_is_dropped_when_another_document_becomes_active() {
let ctx = egui::Context::default();
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
app.session.execute("file.new", json!({"width": 100, "height": 80, "depth": 8})).unwrap();
app.session.execute("layer.new.layer", json!({})).unwrap();
app.session
.edit("paint", |doc, active| {
doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap().fill_rect(Rect::new(20, 30, 80, 50), &[1.0, 0.0, 0.0, 1.0]);
Ok(())
})
.unwrap();
app.sync_views();
crate::distort_ui::menu(&mut app, &ctx, "edit.puppetWarp", &json!({})).unwrap().unwrap();
crate::distort_ui::drop_foreign(&mut app);
assert!(app.distort.puppet.is_some());
app.session.execute("file.new", json!({"width": 32, "height": 32, "depth": 8})).unwrap();
assert!(crate::distort_ui::display_doc(&app, 1).is_some());
crate::distort_ui::drop_foreign(&mut app);
assert!(app.distort.puppet.is_none());
assert!(crate::distort_ui::display_doc(&app, 1).is_none());
// Closing the document it was started on drops it too.
assert!(app.session.set_active(0));
crate::distort_ui::menu(&mut app, &ctx, "edit.puppetWarp", &json!({})).unwrap().unwrap();
crate::distort_ui::drop_foreign(&mut app);
assert!(app.distort.puppet.is_some());
assert!(app.session.close(0).is_some());
crate::distort_ui::drop_foreign(&mut app);
assert!(app.distort.puppet.is_none());
}
/// #4440: ⌘Z / ⌘⇧Z undo and redo pin edits while Puppet Warp is open: placing a pin,
/// dragging one and removing one are a step each; a click that moves nothing isn't one.
#[test]