diff --git a/crates/engine/src/interaction.rs b/crates/engine/src/interaction.rs index a2b9417461..bdc829fb37 100644 --- a/crates/engine/src/interaction.rs +++ b/crates/engine/src/interaction.rs @@ -10,6 +10,9 @@ pub struct Interaction { pub doc: Arc, /// The selection the previews start from (shared, so a preview frame copies nothing). pub selection: Arc, + /// The document's [`crate::DocState::revision`] when the interaction began. The previews change the document's + /// revision, and this value stays the same until the interaction ends. + pub revision: u64, pub preview: Option<(String, Value)>, /// The active tool began it (a drag): a command from outside the tool runs as a step of its /// own under it ([`crate::Session::outside_interaction`]). A dialog or a panel that begins an diff --git a/crates/engine/src/session/edit.rs b/crates/engine/src/session/edit.rs index d5d62e607c..0d2eaaef03 100644 --- a/crates/engine/src/session/edit.rs +++ b/crates/engine/src/session/edit.rs @@ -545,6 +545,7 @@ impl Session { effect: None, doc: st.doc.clone(), selection: Arc::new(st.selection.clone()), + revision: st.revision, preview: None, tool: false, paint, diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index ae6956a288..a51642ee92 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -841,6 +841,35 @@ fn the_move_of_a_releasing_frame_counts_for_the_tool_drag() { assert_eq!(draw(true), Rect::new(130.0, 115.0, 160.0, 130.0), "with Space held through the release the last move moves it"); } +/// A Selection tool move builds the menus' states again twice, in the frame of its press and in the frame of its +/// release, which commits the move. The frame the move begins in and the frames of its previews, which change the +/// document's revision, keep them. +#[test] +fn a_selection_move_rebuilds_the_menus_for_its_press_and_release_only() { + let (mut app, ctx, xf) = rectangle_tool(); + let id = app.session.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 60, "height": 30})).unwrap()["id"].as_u64().unwrap(); + app.select_tool("selection"); + app.session.execute("select.set", &json!({"ids": [id]})).unwrap(); + let (from, to) = (xf.to_screen(Point::new(130.0, 115.0)), xf.to_screen(Point::new(170.0, 135.0))); + app_step(&mut app, &ctx, vec![egui::Event::PointerMoved(from)]); + for _ in 0..2 { + app_step(&mut app, &ctx, vec![]); + } + let none = egui::Modifiers::NONE; + let mut steps = vec![vec![primary(from, true, none)]]; + steps.extend((1..=8).map(|i| vec![egui::Event::PointerMoved(from.lerp(to, i as f32 / 8.0))])); + steps.push(vec![primary(to, false, none)]); + steps.extend([vec![], vec![], vec![]]); + let mut rebuilt = vec![]; + for events in steps { + let before = app.menus.rebuilds; + app_step(&mut app, &ctx, events); + rebuilt.push(app.menus.rebuilds - before); + } + assert_eq!(drawn_paths(&app), vec![Rect::new(140.0, 120.0, 200.0, 150.0)], "the drag moves the rectangle"); + assert_eq!(rebuilt, [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], "rebuilds in each frame: press, 8 moves, release, 3 idle"); +} + /// #6369: only the selection box remains over the temporary halftone, and the original /// selection's outlines come back when Preview is turned off or the dialog is cancelled. #[test] diff --git a/crates/ui-egui/src/menus/model.rs b/crates/ui-egui/src/menus/model.rs index fffff70049..92c1786af4 100644 --- a/crates/ui-egui/src/menus/model.rs +++ b/crates/ui-egui/src/menus/model.rs @@ -89,8 +89,8 @@ pub(crate) fn translate_label(english: &'static str) -> String { /// button pressed or released or a key pressed ([`last_press`]), changes once for each, which covers what the hash /// doesn't list (panels shown, a tool picked). While an /// interaction is open (for example a move, scale or shape drag, a dialog's or the font menu's -/// preview, or a typing session), the revision, which each of its previews changes, is left out: -/// the hash changes as the interaction begins and as it ends. +/// preview, or a typing session), the hash takes the revision the interaction began from in place of the current one, +/// which each of its previews changes: the hash stays the same as the interaction begins, and changes as it ends. pub(crate) fn state_key(app: &VectorcraftApp, input: Option) -> u64 { let mut h = DefaultHasher::new(); input.hash(&mut h); @@ -101,7 +101,7 @@ pub(crate) fn state_key(app: &VectorcraftApp, input: Option) -> u64 { let s = &app.session; (s.journal.len(), s.active_index(), s.clipboard.is_empty(), s.tool_composing()).hash(&mut h); if let Some(d) = s.active() { - let revision = d.interaction.is_none().then_some(d.revision); + let revision = d.interaction.as_ref().map_or(d.revision, |it| it.revision); (d.uid, revision, d.history.undo.len(), d.history.redo.len(), d.transparency_grid, d.print_tiling).hash(&mut h); } (app.system_paste, app.last_effect.is_some(), app.ui.recent_files.len(), app.ui.recent_files.first(), app.recent_fonts().len()).hash(&mut h);