mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 01:18:43 +00:00
fix(ui): drop a Patch drag when its document is reopened and edited (#11024)
A document closed and reopened with the same ID, then edited past the pressed revision before the next frame, kept a stale Patch or Content-Aware Move drag alive. DragDocument now also records the session's active generation, which closing and reopening advance. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b6687511fa
commit
d66bab2ae1
2 files changed
+20
-14
No files matched your search
@@ -385,12 +385,15 @@ pub(crate) fn draw_readout<const N: usize>(ctx: &egui::Context, id: &str, cursor
|
||||
);
|
||||
}
|
||||
|
||||
/// The document a drag was pressed on. A reopened document can keep its ID (and revision), so the
|
||||
/// snapshot tells it apart; an ordinary edit replaces the snapshot but advances the revision, which
|
||||
/// keeps the drag on it (the rule `sync_views` applies to the Paths selection).
|
||||
/// The document a drag was pressed on. A reopened document can keep its ID and revision, and be
|
||||
/// edited past it before the next frame, so the session's active generation, which closing and
|
||||
/// reopening advance, tells it apart; the snapshot catches one replaced in place. An ordinary edit
|
||||
/// replaces the snapshot but advances the revision, which keeps the drag on it (the rule
|
||||
/// `sync_views` applies to the Paths selection).
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DragDocument {
|
||||
id: photocraft_doc::DocId,
|
||||
generation: u64,
|
||||
revision: u64,
|
||||
snapshot: std::sync::Weak<Document>,
|
||||
}
|
||||
@@ -398,14 +401,16 @@ pub struct DragDocument {
|
||||
impl DragDocument {
|
||||
pub fn capture(app: &PhotocraftApp) -> Option<Self> {
|
||||
let st = app.session.active()?;
|
||||
Some(Self { id: st.doc.id, revision: st.revision, snapshot: std::sync::Arc::downgrade(&st.doc) })
|
||||
Some(Self { id: st.doc.id, generation: app.session.active_generation(), revision: st.revision, snapshot: std::sync::Arc::downgrade(&st.doc) })
|
||||
}
|
||||
|
||||
/// The document is still the active one.
|
||||
pub fn is_active(&self, app: &PhotocraftApp) -> bool {
|
||||
app.session
|
||||
.active()
|
||||
.is_some_and(|st| st.doc.id == self.id && (st.revision > self.revision || self.snapshot.ptr_eq(&std::sync::Arc::downgrade(&st.doc))))
|
||||
app.session.active_generation() == self.generation
|
||||
&& app
|
||||
.session
|
||||
.active()
|
||||
.is_some_and(|st| st.doc.id == self.id && (st.revision > self.revision || self.snapshot.ptr_eq(&std::sync::Arc::downgrade(&st.doc))))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -504,13 +504,14 @@ fn a_patch_drag_is_dropped_when_another_document_is_active() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A document closed and reopened with the same ID and revision mid-drag is another document: the
|
||||
/// drag is dropped and its release neither lassos nor patches the reopened one. An ordinary edit
|
||||
/// keeps the drag (#11024 review).
|
||||
/// A document closed and reopened with the same ID mid-drag is another document, whether it comes
|
||||
/// back at the same revision or is edited past it: the drag is dropped and its release neither
|
||||
/// lassos nor patches the reopened one. An ordinary edit keeps the drag (#11024 review).
|
||||
#[test]
|
||||
fn a_patch_drag_is_dropped_when_its_document_is_reopened_with_the_same_id() {
|
||||
for tool in [Tool::Patch, Tool::ContentAwareMove] {
|
||||
for reopen in [false, true] {
|
||||
// (reopened, revisions the reopened document is edited past the pressed one)
|
||||
for (reopen, edits) in [(false, 0), (true, 0), (true, 1)] {
|
||||
let mut app = app();
|
||||
app.run("select.rect", json!({"x": 10, "y": 20, "width": 16, "height": 20})).unwrap();
|
||||
app.ui.tool = tool;
|
||||
@@ -519,17 +520,17 @@ fn a_patch_drag_is_dropped_when_its_document_is_reopened_with_the_same_id() {
|
||||
if reopen {
|
||||
let closed = app.session.close(0).unwrap();
|
||||
app.session.add_document((*closed.doc).clone(), None);
|
||||
app.session.active_mut().unwrap().revision = closed.revision;
|
||||
app.session.active_mut().unwrap().revision = closed.revision + edits;
|
||||
assert_eq!(app.session.active().unwrap().doc.id, closed.doc.id, "a reopened document may keep its ID");
|
||||
} else {
|
||||
app.run("layer.new.layer", json!({})).unwrap();
|
||||
}
|
||||
app.sync_views();
|
||||
assert_eq!(app.drag.is_some(), !reopen, "{tool:?}: reopened {reopen}");
|
||||
assert_eq!(app.drag.is_some(), !reopen, "{tool:?}: reopened {reopen}, edited {edits}");
|
||||
tool_event(&mut app, ToolEvent::Up { x: 60.0, y: 40.0 }, egui::Modifiers::NONE);
|
||||
let sel = app.session.active().unwrap().doc.selection.clone().unwrap();
|
||||
let lassoed = sel.content_bounds() != photocraft_geom::Rect::new(10, 20, 26, 40);
|
||||
assert_eq!(lassoed, !reopen, "{tool:?}: reopened {reopen}: {:?}", sel.content_bounds());
|
||||
assert_eq!(lassoed, !reopen, "{tool:?}: reopened {reopen}, edited {edits}: {:?}", sel.content_bounds());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user