diff --git a/crates/engine/src/session/execute.rs b/crates/engine/src/session/execute.rs index 0ba94dffa2..f87d37691f 100644 --- a/crates/engine/src/session/execute.rs +++ b/crates/engine/src/session/execute.rs @@ -100,8 +100,10 @@ impl Session { } let outer = std::mem::replace(&mut self.reading, !spec.journal || JOURNALED_READS.contains(&id)); // A command from outside the tool, while the tool's drag is in progress, is a step of its - // own before the drag's ([`Session::outside_interaction`]). - let outside = spec.journal && !self.previewing && !self.in_tool_actions; + // own before the drag's ([`Session::outside_interaction`]). Find Objects with `select` is + // journaled (`Session::journal_query`), so it is one too. + let find_selects = id == "document.find" && params.get("select").and_then(Value::as_bool) == Some(true); + let outside = (spec.journal || find_selects) && !self.previewing && !self.in_tool_actions; // A preview that a top-level command applied first (a drag with Real-time Drawing off, kept // before Undo) reports its warning in the command's result. let r = if self.depth == 0 { diff --git a/crates/engine/src/tests/interaction_commands.rs b/crates/engine/src/tests/interaction_commands.rs index 71e23f6382..5234ea52ac 100644 --- a/crates/engine/src/tests/interaction_commands.rs +++ b/crates/engine/src/tests/interaction_commands.rs @@ -432,6 +432,30 @@ fn a_move_drag_after_a_selection_command_replays_on_its_own_object() { } } +/// Find Objects with `select` during a drag is a step of its own, as it is journaled: it finds and +/// selects only the objects outside the drag's preview, as its replay before the drag does. +#[test] +fn find_objects_with_select_during_a_drag_skips_the_drag_preview() { + for real_time in [true, false] { + let at = format!("real time {real_time}"); + let (mut s, other) = session(real_time); + let start = s.journal.len(); + let find = json!({"intersects": [0, 0, 400, 400], "select": true}); + pointer(&mut s, PointerKind::Down, 100.0, 100.0); + pointer(&mut s, PointerKind::Drag, 150.0, 150.0); + let r = s.execute("document.find", &find).unwrap(); + assert_eq!(r["total"], 1, "{at}: {r}"); + assert_eq!(r["matches"][0]["id"], other.0, "{at}: {r}"); + pointer(&mut s, PointerKind::Up, 200.0, 180.0); + assert_eq!(objects(&s), 2, "{at}: the release draws the rectangle"); + assert_eq!(journaled(&s, start), ["document.find", "shape.rectangle"], "{at}"); + let (mut replayed, _) = session(real_time); + replay_from(&s, start, &mut replayed); + assert_eq!(objects(&replayed), 2, "{at}"); + assert_eq!(replayed.doc().unwrap().selection.objects, s.doc().unwrap().selection.objects, "{at}"); + } +} + /// A square on a second layer selected with a ruler guide, and a square on the first layer → /// the session (with Real-time Drawing `real_time`) and the square on the first layer. fn square_and_guide(real_time: bool) -> (Session, NodeId) {