From ece910a3b72fb8477f7c74756459941fa7f9b2d8 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 16:45:24 -0800 Subject: [PATCH] Selection: a Cmd double-click after switching back is the active tool's A switch from the Selection tool to another tool and back kept the record of the selection tool Cmd lent the last press, so the Cmd double-click that followed still went to Direct Selection. The record is now cleared whenever the active tool changes and whenever the tool starts afresh (a switch to another document or another view of it). --- crates/engine/src/lib.rs | 4 ++-- crates/engine/src/session/documents.rs | 1 + crates/engine/src/tests/draw2.rs | 30 ++++++++++++++++++++++++++ crates/engine/src/tooling.rs | 3 +++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 244da31e5d..b213394c0c 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -111,8 +111,8 @@ pub struct Session { 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, 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. + /// lent from: a follow-up in another document, after a tool switch (also one back to the same + /// tool) or after the tool starts afresh 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 diff --git a/crates/engine/src/session/documents.rs b/crates/engine/src/session/documents.rs index 7930095b6e..e800a9c572 100644 --- a/crates/engine/src/session/documents.rs +++ b/crates/engine/src/session/documents.rs @@ -209,6 +209,7 @@ impl Session { return; } self.press_type_selection = None; + self.press_lent = None; let view = self.last_view; // The edit the tool computes on another thread and the input held for it belong to the // document being left. The switch goes on whatever they did, as for the deactivation. diff --git a/crates/engine/src/tests/draw2.rs b/crates/engine/src/tests/draw2.rs index 740b99f42a..34254b3513 100644 --- a/crates/engine/src/tests/draw2.rs +++ b/crates/engine/src/tests/draw2.rs @@ -4801,6 +4801,36 @@ fn a_cmd_double_click_after_a_tool_switch_goes_to_the_new_tool() { assert_eq!(s.tool_id(), "groupSelection"); } +#[test] +fn a_cmd_double_click_after_switching_away_and_back_goes_to_the_active_tool() { + // A Cmd-click with the Selection tool goes to Direct Selection. After a switch to another tool + // and back to the Selection tool, or a fresh start of the tool (another view of the document), + // the Cmd double-click is the Selection tool's: it isolates the group. + let cmd = Mods { cmd: true, ..Mods::default() }; + let v = view(); + let mut s = session(); + let a = rect(&mut s, 100.0, 100.0, 100.0, 100.0); + let b = rect(&mut s, 300.0, 100.0, 100.0, 100.0); + s.execute("object.group", &json!({"ids": [a.0, b.0]})).unwrap(); + for reset in [false, true] { + s.execute("select.none", &json!({})).unwrap(); + s.select_tool("selection", v).unwrap(); + for kind in [PointerKind::Down, PointerKind::Up] { + s.pointer(&PointerEvent::new(kind, 150.0, 150.0).with_mods(cmd), v).unwrap(); + } + if reset { + s.reset_tool(); + } else { + s.select_tool("rectangle", v).unwrap(); + s.select_tool("selection", v).unwrap(); + } + s.pointer(&PointerEvent::new(PointerKind::DoubleClick, 150.0, 150.0).with_mods(cmd), v).unwrap(); + assert_eq!(s.tool_id(), "selection"); + assert!(s.doc().unwrap().isolation.is_some(), "the Selection tool's double-click isolates the group (reset: {reset})"); + s.execute("object.exitIsolation", &json!({})).unwrap(); + } +} + #[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 b023ca1f7f..761c9af469 100644 --- a/crates/engine/src/tooling.rs +++ b/crates/engine/src/tooling.rs @@ -198,6 +198,9 @@ impl Session { if self.tool.id() == id { return Ok(()); } + // A double-click or triple-click after the switch is the new tool's, also when the switch + // comes back to the tool a Cmd press was lent from. + self.press_lent = None; // Sampling type keeps its highlighted characters as the target, and a whole story that // Select All selected. Capture before the Type tool deactivates (which commits typing and // clears its editing state).