From 1e0e8f78dc1be7c34950140fe9b1c0edd193e29f Mon Sep 17 00:00:00 2001 From: phanoob Date: Tue, 20 Oct 2026 20:29:22 +0000 Subject: [PATCH] Shift+R repeats the last tool or dialog (#3045) (#3160) * claim: #3045 Co-Authored-By: Claude Opus 5.5 * Shift+R repeats the last tool or dialog (#3045) Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Phanoob Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/context_menu.rs | 10 ++++------ crates/ui-egui/src/keymap.rs | 31 ++++++++++++++++++++++++++++++ crates/ui-egui/src/lib.rs | 8 ++++++++ crates/ui-egui/src/toolbar.rs | 3 +++ 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/context_menu.rs b/crates/ui-egui/src/context_menu.rs index da64bd183..9d864045b 100644 --- a/crates/ui-egui/src/context_menu.rs +++ b/crates/ui-egui/src/context_menu.rs @@ -307,8 +307,8 @@ pub fn component_bodies(app: &SolveApp, id: u64) -> Vec { /// The eight radial commands, clockwise from the top. pub fn radial_items(app: &SolveApp) -> Vec { let repeat = match &app.last_command { - Some((_, label)) => act("ui.repeat", &format!("Repeat {label}"), "redo"), - None => act("ui.repeat", "Repeat", "redo").on(false), + Some((_, label)) => act("ui.repeat", &format!("Repeat {label}"), "redo").key(crate::keymap::REPEAT_KEY), + None => act("ui.repeat", "Repeat", "redo").key(crate::keymap::REPEAT_KEY).on(false), }; let delete = act("ui.delete", "Delete", "delete").key("Del").on(!app.session.selection.is_empty()); if app.session.active_sketch.is_some() { @@ -464,7 +464,7 @@ fn viewport_items(app: &SolveApp) -> Vec { let has = |f: fn(&Sel) -> bool| sel.iter().any(f); let mut v = Vec::new(); if let Some((_, label)) = &app.last_command { - v.push(act("ui.repeat", &format!("Repeat {label}"), "redo")); + v.push(act("ui.repeat", &format!("Repeat {label}"), "redo").key(crate::keymap::REPEAT_KEY)); v.push(Item::sep()); } // Everything under the cursor, for what lies beneath something else. @@ -975,9 +975,7 @@ pub fn run_item(app: &mut SolveApp, item: &Item, at: Pos2) { } } "ui.repeat" => { - if let Some((id, _)) = app.last_command.clone() { - app.start(&id); - } + app.repeat_last(); } "ui.selectOther" => { crate::select_other::open(app, at); diff --git a/crates/ui-egui/src/keymap.rs b/crates/ui-egui/src/keymap.rs index c1c1bd8a3..4567000b5 100644 --- a/crates/ui-egui/src/keymap.rs +++ b/crates/ui-egui/src/keymap.rs @@ -11,8 +11,12 @@ use solidcraft_engine::command_specs; use crate::SolveApp; use crate::ui_kit; +/// Repeats the last tool or dialog started (`SolveApp::repeat_last`, #3045). +pub const REPEAT_KEY: &str = "Shift+R"; + /// Keys the application handles before any command shortcut. pub const RESERVED: &[&str] = &[ + REPEAT_KEY, "Escape", "S", "V", @@ -379,6 +383,33 @@ mod tests { assert_eq!(effective(&b, "solid.move").as_deref(), Some("M")); assert_eq!(key_name(egui::Key::K, egui::Modifiers { ctrl: true, shift: true, ..Default::default() }), "Ctrl+Shift+K"); } + + /// #3045: Shift+R starts the last tool again (here a sketch's Line after Escape put it + /// down), R alone is still the rectangle; the menus show the key on Repeat, and no command + /// can take it. + #[test] + fn shift_r_repeats_the_last_tool() { + let mut h = crate::scenario::Harness::new(); + h.app.home.open = false; + h.app.run("sketch.create", json!({"plane": "XY"})).unwrap(); + h.frames(2); + h.step(&json!({"start": "sketch.line"})).unwrap(); + h.step(&json!({"key": "Escape"})).unwrap(); + h.frames(1); + assert!(h.app.tool.is_none()); + h.step(&json!({"key": "R", "shift": true})).unwrap(); + h.frames(1); + assert_eq!(h.app.tool.as_ref().map(|t| t.cmd.to_string()).as_deref(), Some("sketch.line"), "Shift+R starts Line again"); + h.step(&json!({"key": "Escape"})).unwrap(); + h.step(&json!({"key": "R"})).unwrap(); + h.frames(1); + let rectangle = h.app.tool.as_ref().map(|t| t.cmd.to_string()).unwrap_or_default(); + assert!(rectangle.starts_with("sketch.rectangle"), "R alone: {rectangle}"); + let repeat = crate::context_menu::radial_items(&h.app).into_iter().find(|i| i.id == "ui.repeat").unwrap(); + assert_eq!(repeat.shortcut, REPEAT_KEY); + let mut a = app(); + assert!(bind(&mut a, "solid.extrude", REPEAT_KEY, true).is_err(), "Shift+R is the app's"); + } } #[cfg(test)] diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 36c334595..2f5e5148b 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -810,6 +810,14 @@ impl SolveApp { workspace::sync_context(self); } + /// Start the last tool or dialog started again (Repeat in the menus, Shift+R; #3045). + /// `false` when none was started yet. + pub fn repeat_last(&mut self) -> bool { + let Some((id, _)) = self.last_command.clone() else { return false }; + self.start(&id); + true + } + /// Start a command the way a toolbar click does: interactive tools and dialogs for commands /// that have them, otherwise run it with defaults. pub fn start(&mut self, id: &str) { diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs index 6d280a41b..787254f2a 100644 --- a/crates/ui-egui/src/toolbar.rs +++ b/crates/ui-egui/src/toolbar.rs @@ -1845,6 +1845,9 @@ pub fn shortcuts(app: &mut SolveApp, ctx: &egui::Context) { app.start("ui.palette"); } Key::V => crate::context_menu::toggle_visibility(app), + Key::R if mods.shift && !mods.alt => { + app.repeat_last(); + } Key::F2 => { let at = ctx.input(|i| i.pointer.latest_pos()).unwrap_or(ctx.content_rect().center()); crate::context_menu::rename_selection(app, at);