diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index bbcba38fff..244da31e5d 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -110,8 +110,10 @@ pub struct Session { /// Selection tool. None until one is chosen. pub(crate) last_part_selection_tool: Option<&'static str>, /// The selection tool Cmd lent the last press, which also takes the double-click or - /// triple-click that follows it. None when the press was not lent. - pub(crate) press_lent: Option<&'static str>, + /// triple-click that follows it, with the uid of the document and the id of the tool it was + /// lent from: a follow-up in another document or after a tool switch is not lent. None when + /// the press was not lent. + pub(crate) press_lent: Option<(Option, &'static str, &'static str)>, /// The selection tool a Cmd press would borrow at the pointer, as [`Session::hover_tool_at`] /// or [`Session::cursor`] last found it with Cmd held (None inside when it found none), with /// the document state, active tool and keys it was found for. None when it was last asked diff --git a/crates/engine/src/tests/draw2.rs b/crates/engine/src/tests/draw2.rs index c497fed246..740b99f42a 100644 --- a/crates/engine/src/tests/draw2.rs +++ b/crates/engine/src/tests/draw2.rs @@ -4775,6 +4775,32 @@ fn a_cmd_double_click_goes_to_the_tool_the_clicks_went_to() { assert!(s.doc().unwrap().isolation.is_some()); } +#[test] +fn a_cmd_double_click_after_a_tool_switch_goes_to_the_new_tool() { + // With the Selection tool, a Cmd-click on type goes to Direct Selection, and so does the + // Cmd double-click after it, which edits the type. Once another tool is chosen, the + // double-click is that tool's: Group Selection's does not edit the type. + let cmd = Mods { cmd: true, ..Mods::default() }; + let v = view(); + let mut s = session(); + let id = NodeId(s.execute("text.create", &json!({"x": 100, "y": 200, "size": 48, "text": "Type"})).unwrap()["id"].as_u64().unwrap()); + let c = s.doc().unwrap().doc.node(id).unwrap().geometric_bounds().unwrap().center(); + let clicks = |s: &mut Session, then: Option<&str>| { + s.execute("select.none", &json!({})).unwrap(); + s.select_tool("selection", v).unwrap(); + for kind in [PointerKind::Down, PointerKind::Up] { + s.pointer(&PointerEvent::new(kind, c.x, c.y).with_mods(cmd), v).unwrap(); + } + if let Some(tool) = then { + s.select_tool(tool, v).unwrap(); + } + s.pointer(&PointerEvent::new(PointerKind::DoubleClick, c.x, c.y).with_mods(cmd), v).unwrap() + }; + assert_eq!(clicks(&mut s, None), [UiRequest::SwitchTool("type".into())], "Direct Selection's double-click edits the type"); + assert_eq!(clicks(&mut s, Some("groupSelection")), [], "Group Selection's double-click does not"); + assert_eq!(s.tool_id(), "groupSelection"); +} + #[test] fn a_cmd_press_on_a_selected_object_keeps_select_behind() { // Over a selected object, a Cmd-click with the Selection tool selects the object behind it; diff --git a/crates/engine/src/tooling.rs b/crates/engine/src/tooling.rs index 736b99617a..b023ca1f7f 100644 --- a/crates/engine/src/tooling.rs +++ b/crates/engine/src/tooling.rs @@ -406,11 +406,17 @@ impl Session { if (ev.kind != PointerKind::Down && !follow_up) || !ev.mods.cmd || self.lender.is_some() { return Ok((*ev, vec![])); } - // A follow-up goes where the press before it went, whatever that press selected. - let id = if follow_up { self.press_lent } else { self.lent_tool_at(ev.pos, &ev.mods, view) }; + // A follow-up goes where the press before it went, whatever that press selected, while the + // document and the active tool are the ones that press found. + let at = (self.active().map(|d| d.uid), self.tool.id()); + let id = if follow_up { + self.press_lent.filter(|(doc, tool, _)| (*doc, *tool) == at).map(|(.., id)| id) + } else { + self.lent_tool_at(ev.pos, &ev.mods, view) + }; let Some(id) = id else { return Ok((*ev, vec![])) }; if !follow_up { - self.press_lent = Some(id); + self.press_lent = Some((at.0, at.1, id)); } // Typing in progress is kept as its own step first: the lent tool's drag previews from the // document its interaction started from, which would drop the typing (#1881). When it