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).
This commit is contained in:
dotCooCoo committed 2026-11-22 16:45:24 -08:00
1 parent 2592dde6c8
commit ece910a3b7
4 files changed
+36 -2

No files matched your search

+2 -2
View File
@@ -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<u64>, &'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
+1
View File
@@ -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.
+30
View File
@@ -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;
+3
View File
@@ -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).