diff --git a/assets/locales/en.json b/assets/locales/en.json index 13c53e0db..aa43f6d49 100644 --- a/assets/locales/en.json +++ b/assets/locales/en.json @@ -2248,6 +2248,8 @@ "ui.shortcut_capture_press": "Press modifiers and one key. Escape cancels.", "ui.shortcut_capture_release": "Release all keys to confirm. Escape cancels.", "ui.shortcut_capture_settling": "Confirming shortcut… Escape cancels.", + "ui.shortcut_cycles_modes": "Pressing a tool's shortcut again switches its mode", + "ui.shortcut_cycles_modes_tip": "Before the first point, pressing a sketch tool's shortcut again steps through its creation modes. Off: it starts the tool again.", "ui.shortcut_multiple_keys": "Use modifiers and only one other key. Click the binding to try again.", "ui.show": "Show", "ui.showAll": "Show All", diff --git a/assets/locales/ja.json b/assets/locales/ja.json index 8ff94cd5e..063ae9574 100644 --- a/assets/locales/ja.json +++ b/assets/locales/ja.json @@ -2248,6 +2248,8 @@ "ui.shortcut_capture_press": "修飾キーと1つのキーを押してください。Escでキャンセルします。", "ui.shortcut_capture_release": "すべてのキーを離すと確定します。Escでキャンセルします。", "ui.shortcut_capture_settling": "ショートカットを確定中… Escでキャンセルします。", + "ui.shortcut_cycles_modes": "ツールのショートカットをもう一度押すとモードを切り替える", + "ui.shortcut_cycles_modes_tip": "最初の点を置く前にスケッチツールのショートカットをもう一度押すと、作成モードを順に切り替えます。オフ: ツールを最初から始めます。", "ui.shortcut_multiple_keys": "修飾キーと、それ以外のキー1つだけを使用してください。割り当てをクリックしてやり直してください。", "ui.show": "表示", "ui.showAll": "すべて表示", diff --git a/assets/locales/zh.json b/assets/locales/zh.json index cd58e2b54..8797c06ca 100644 --- a/assets/locales/zh.json +++ b/assets/locales/zh.json @@ -2248,6 +2248,8 @@ "ui.shortcut_capture_press": "请按修饰键和一个普通键。按 Esc 取消。", "ui.shortcut_capture_release": "松开所有键以确认。按 Esc 取消。", "ui.shortcut_capture_settling": "正在确认快捷键… 按 Esc 取消。", + "ui.shortcut_cycles_modes": "再次按下工具的快捷键时切换其模式", + "ui.shortcut_cycles_modes_tip": "在放置第一个点之前,再次按下草图工具的快捷键会依次切换其创建模式。关闭:重新开始该工具。", "ui.shortcut_multiple_keys": "请使用修饰键和一个普通键。点击快捷键重试。", "ui.show": "显示", "ui.showAll": "显示全部", diff --git a/crates/ui-egui/src/keymap.rs b/crates/ui-egui/src/keymap.rs index eaa3b4594..9db78551b 100644 --- a/crates/ui-egui/src/keymap.rs +++ b/crates/ui-egui/src/keymap.rs @@ -286,8 +286,23 @@ pub fn command_for(app: &SolveApp, key: &str) -> Option<&'static str> { /// Run a shortcut key: its enabled command; outside a sketch, a sketch tool's key opens Create /// Sketch (on the selected plane or planar face, else on the plane picked next) and the tool /// starts in the new sketch. -pub fn press(app: &mut SolveApp, key: &str) { +pub fn press(app: &mut SolveApp, key: &str, repeat: bool) { if let Some(id) = command_for(app, key) { + // Pressed again while a tool of the same family is out, with Preferences › Sketch asking + // for it (#2459): before its first point, the family's next mode (wrapping round); once a + // point is placed, the tool keeps it. A held key's repeats change nothing. + if let Some((family, current, started)) = app.tool.as_ref().filter(|_| app.preferences.shortcut_cycles_modes).and_then(|t| { + let f = crate::sketch_families::family(t.cmd).filter(|f| f.commands.contains(&id))?; + Some((f, t.cmd, !t.pts.is_empty() || !t.picks.is_empty())) + }) { + if !repeat && !started { + let at = family.commands.iter().position(|c| *c == current).unwrap_or(0); + if let Some(next) = family.commands.get((at + 1) % family.commands.len()) { + app.start(next); + } + } + return; + } app.start(app.preferences.sketch_variants.resolve(id)); } else if let Some(id) = sketch_tool_for(app, key) { app.start("sketch.create"); diff --git a/crates/ui-egui/src/menu_tests.rs b/crates/ui-egui/src/menu_tests.rs index 37b976968..86497b4ee 100644 --- a/crates/ui-egui/src/menu_tests.rs +++ b/crates/ui-egui/src/menu_tests.rs @@ -304,10 +304,10 @@ fn move_shortcut_uses_the_selected_nested_instance_and_pending_position() { let baseline = app.session.pending_moves[&child]; app.run("select.set", json!({"items":[{"type":"occurrence","path":path}]})).unwrap(); crate::keymap::bind(&mut app, "solid.move", "Shift+M", false).unwrap(); - crate::keymap::press(&mut app, "M"); + crate::keymap::press(&mut app, "M", false); assert!(app.tree.occurrence_move.is_none(), "the old shortcut was cleared"); app.ui.tab = "INSPECT".into(); - crate::keymap::press(&mut app, "Shift+M"); + crate::keymap::press(&mut app, "Shift+M", false); assert_eq!(app.ui.tab, "MODEL", "starting component Move still selects the command's workspace tab"); let movement = app.tree.occurrence_move.as_ref().expect("component Move opens from its rebound shortcut"); assert_eq!(movement.occurrence, child); @@ -325,13 +325,13 @@ fn move_shortcut_respects_grounding_and_keeps_body_selection_as_a_body_move() { app.run("solid.box", json!({"length":30,"width":20,"height":10})).unwrap(); app.run("occurrence.ground", json!({"occurrence":occurrence,"grounded":true})).unwrap(); app.run("select.set", json!({"items":[{"type":"occurrence","path":[occurrence]}]})).unwrap(); - crate::keymap::press(&mut app, "M"); + crate::keymap::press(&mut app, "M", false); assert!(app.tree.occurrence_move.is_none(), "a grounded component cannot move"); assert!(app.dialog.is_none(), "do not fall back to moving the grounded component's bodies"); app.run("occurrence.ground", json!({"occurrence":occurrence,"grounded":false})).unwrap(); app.run("select.set", json!({"items":[{"type":"body","name":"Body1"}]})).unwrap(); - crate::keymap::press(&mut app, "M"); + crate::keymap::press(&mut app, "M", false); assert!(app.tree.occurrence_move.is_none(), "a body selection still edits geometry"); let dialog = app.dialog.as_ref().expect("body Move opens"); assert!(matches!(dialog.kind, crate::dialogs::Kind::Move { .. })); diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs index e3f314c44..f9c243fbd 100644 --- a/crates/ui-egui/src/prefs.rs +++ b/crates/ui-egui/src/prefs.rs @@ -651,6 +651,9 @@ preference_settings! { suppress_sketch_snap: ModifierCombo = ModifierCombo::CTRL_ALT, PAGE_SKETCH; /// Whether Alt/Option also frees gizmo / canvas manipulator arrows (Primary always does). manipulator_free_alt: bool = true, PAGE_SKETCH; + /// A sketch tool's shortcut pressed again before the first point steps to the tool's next + /// creation mode (#2459). Off (the default): the key starts the tool again, as it always has. + shortcut_cycles_modes: bool = false, PAGE_SKETCH; /// When true: Shift+click adds without removing; Primary toggles. /// When false (default): Shift and Primary both toggle. selection_shift_add_only: bool = false, PAGE_SKETCH; diff --git a/crates/ui-egui/src/prefs/sketch.rs b/crates/ui-egui/src/prefs/sketch.rs index 67cd1ec4a..ac6a8b198 100644 --- a/crates/ui-egui/src/prefs/sketch.rs +++ b/crates/ui-egui/src/prefs/sketch.rs @@ -9,6 +9,10 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) { if ui_kit::checkbox(ui, crate::i18n::tr_label("Project face edges into new sketches"), &mut auto).changed() { let _ = app.run("sketch.auto_project", json!({"value": auto})); } + ui_kit::checkbox(ui, crate::i18n::tr_label("Pressing a tool's shortcut again switches its mode"), &mut app.preferences.shortcut_cycles_modes) + .on_hover_text(crate::i18n::tr_label( + "Before the first point, pressing a sketch tool's shortcut again steps through its creation modes. Off: it starts the tool again.", + )); ui_kit::settings_block_hint(ui, app.tr("prefs.hold_stop_snapping"), app.tr("prefs.snap_drawing_note"), t.space_24 * 8.0 + t.space_8, |ui| { let combo = &mut app.preferences.suppress_sketch_snap; ui_kit::settings_control_width(ui, t.space_24 * 7.0 + t.space_12, |ui| { diff --git a/crates/ui-egui/src/sketch_shortcut_tests.rs b/crates/ui-egui/src/sketch_shortcut_tests.rs index 7be7f41d7..668455e8a 100644 --- a/crates/ui-egui/src/sketch_shortcut_tests.rs +++ b/crates/ui-egui/src/sketch_shortcut_tests.rs @@ -148,3 +148,49 @@ fn move_key_keeps_sketch_mode_behavior_and_honors_a_sketch_move_binding() { assert_eq!(h.app.session.active_sketch, sketch); assert!(h.app.tree.occurrence_move.is_none(), "M must not open component Move while editing its sketch"); } + +/// #2459: by default a tool's shortcut pressed again starts the tool again, in the mode the key +/// is bound to; the preference is off. +#[test] +fn a_tools_shortcut_pressed_again_restarts_it_by_default() { + let mut h = Harness::new(); + assert!(!h.app.preferences.shortcut_cycles_modes, "off by default"); + h.app.run("sketch.create", json!({"plane": "XY"})).unwrap(); + h.settle(); + press(&mut h, "R"); + assert_eq!(tool(&h), Some("sketch.rectangle.two_point")); + press(&mut h, "R"); + assert_eq!(tool(&h), Some("sketch.rectangle.two_point"), "the same mode again"); +} + +/// #2459: with Preferences › Sketch asking for it, a tool's shortcut pressed again before the +/// first point steps through its family's modes and wraps round; a held key's repeats and a shape +/// already begun keep the tool. +#[test] +fn a_tools_shortcut_pressed_again_cycles_its_modes() { + let mut h = Harness::new(); + h.app.preferences.shortcut_cycles_modes = true; + h.app.run("sketch.create", json!({"plane": "XY"})).unwrap(); + h.settle(); + press(&mut h, "R"); + assert_eq!(tool(&h), Some("sketch.rectangle.two_point"), "the first press starts the bound mode"); + for want in ["sketch.rectangle.three_point", "sketch.rectangle.center", "sketch.rectangle.rounded", "sketch.rectangle.two_point"] { + press(&mut h, "R"); + assert_eq!(tool(&h), Some(want)); + } + // Auto-repeat of a held R doesn't skip modes. + crate::keymap::press(&mut h.app, "R", true); + assert_eq!(tool(&h), Some("sketch.rectangle.two_point"), "a repeat changes nothing"); + // Another tool's key starts that tool, at its bound mode. + press(&mut h, "C"); + assert_eq!(tool(&h), Some("sketch.circle.center")); + press(&mut h, "C"); + assert_eq!(tool(&h), Some("sketch.circle.two_point")); + // Once the shape is begun, its key keeps the tool and the point. + press(&mut h, "R"); + h.step(&json!({"click": {"world": [0, 0, 0]}})).unwrap(); + assert_eq!(h.app.tool.as_ref().map(|t| t.pts.len()), Some(1)); + press(&mut h, "R"); + assert_eq!(tool(&h), Some("sketch.rectangle.two_point")); + assert_eq!(h.app.tool.as_ref().map(|t| t.pts.len()), Some(1), "the placed corner is kept"); +} diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs index 6c57a8ddd..eff47128a 100644 --- a/crates/ui-egui/src/toolbar.rs +++ b/crates/ui-egui/src/toolbar.rs @@ -1989,7 +1989,7 @@ pub fn shortcuts(app: &mut SolveApp, ctx: &egui::Context) { // Copy, Cut and Paste (`edit_clipboard::handle`). Key::C | Key::X | Key::V if !mods.shift && !mods.alt => {} Key::S => save(app), - _ => crate::keymap::press(app, &crate::keymap::key_name(k, mods)), + _ => crate::keymap::press(app, &crate::keymap::key_name(k, mods), repeat), } continue; } @@ -2061,7 +2061,7 @@ pub fn shortcuts(app: &mut SolveApp, ctx: &egui::Context) { crate::viewport::delete_selection(app); } } - _ => crate::keymap::press(app, &crate::keymap::key_name(k, mods)), + _ => crate::keymap::press(app, &crate::keymap::key_name(k, mods), repeat), } } }