SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Keys: option to keep model keys out of sketches (#7675)
dudedagger426be5be7f0c20
diff --git a/assets/locales/pending/sketch-keys-only.json b/assets/locales/pending/sketch-keys-only.jsonnew file mode 100644index 0000000000..685c6dbd0c--- /dev/null+++ b/assets/locales/pending/sketch-keys-only.json@@ -0,0 +1,26 @@+{+ "en": {+ "ui.sketch_keys_only": "Keep model keys out of sketches",+ "ui.sketch_keys_only_tip": "While editing a sketch, only sketch keys and keys that work everywhere run; a model key such as E or F does nothing, so a stray key can't close a heavy sketch."+ },+ "ar": {+ "ui.sketch_keys_only": "إبقاء مفاتيح النموذج خارج الرسومات",+ "ui.sketch_keys_only_tip": "أثناء تحرير رسم، تعمل مفاتيح الرسم والمفاتيح التي تعمل في كل مكان فقط؛ ولا يفعل مفتاح نموذج مثل E أو F شيئًا، فلا يمكن لمفتاح مضغوط بالخطأ أن يغلق رسمًا ثقيلًا."+ },+ "he": {+ "ui.sketch_keys_only": "להשאיר את מקשי המודל מחוץ לסקיצות",+ "ui.sketch_keys_only_tip": "בזמן עריכת סקיצה פועלים רק מקשי סקיצה ומקשים שפועלים בכל מקום; מקש של המודל כמו E או F לא עושה דבר, כך שמקש שנלחץ בטעות לא יסגור סקיצה כבדה."+ },+ "ja": {+ "ui.sketch_keys_only": "スケッチ中はモデルのキーを使わない",+ "ui.sketch_keys_only_tip": "スケッチの編集中は、スケッチのキーとどこでも使えるキーだけが働きます。E や F などのモデルのキーは何もしないので、うっかり押したキーで重いスケッチが閉じることはありません。"+ },+ "vi": {+ "ui.sketch_keys_only": "Không dùng phím mô hình trong bản phác thảo",+ "ui.sketch_keys_only_tip": "Khi đang chỉnh sửa bản phác thảo, chỉ các phím phác thảo và các phím dùng được ở mọi nơi mới hoạt động; phím mô hình như E hoặc F không làm gì, nên một phím bấm nhầm không thể đóng một bản phác thảo nặng."+ },+ "zh": {+ "ui.sketch_keys_only": "草图中不使用模型快捷键",+ "ui.sketch_keys_only_tip": "编辑草图时,只有草图快捷键和在任何地方都可用的快捷键会生效;E 或 F 等模型快捷键不起作用,因此误按的按键不会关闭复杂的草图。"+ }+}diff --git a/crates/ui-egui/src/keymap.rs b/crates/ui-egui/src/keymap.rsindex e5d869ab71..63706840fa 100644--- a/crates/ui-egui/src/keymap.rs+++ b/crates/ui-egui/src/keymap.rs@@ -379,14 +379,14 @@ pub fn commands_for(app: &SolveApp, key: &str) -> Vec<&'static str> {/// Where a command's shortcut works: in a sketch (the SKETCH tab's tools), in the model (the/// other tabs), or everywhere (commands on no tab: undo, views, files).#[derive(Clone, Copy, PartialEq, Eq, Debug)]-enum Scope {+pub(crate) enum Scope {Render,Sketch,Model,Everywhere,}-fn scope(id: &str) -> Scope {+pub(crate) fn scope(id: &str) -> Scope {if id.starts_with("render.") || matches!(id, "appearance.paint" | "appearance.pick_up") {return Scope::Render;}@@ -405,8 +405,17 @@ fn clash(a: &str, b: &str) -> bool {x == y || x == Scope::Everywhere || y == Scope::Everywhere}+/// Whether a command's key runs in a sketch and in the model alike when the two keep their keys+/// apart: one of no tab, and inspecting, views and files wherever their buttons sit (Measure's I).+fn runs_everywhere(id: &str) -> bool {+ scope(id) == Scope::Everywhere || ["inspect.", "view.", "file."].iter().any(|p| id.starts_with(p))+}+/// The enabled command a key press runs, if any: one of the mode the view is in (a sketch tool-/// while a sketch is open, a model command otherwise) before any other.+/// while a sketch is open, a model command otherwise) before any other. With Preferences ›+/// Shortcuts › Keep model keys out of sketches on, only one of that mode or one that works+/// everywhere: a model command's key pressed in a sketch (E, F) runs nothing, nor a sketch+/// tool's in the model.pub fn command_for(app: &SolveApp, key: &str) -> Option<&'static str> {let here = if crate::render_workspace::active(app) {Scope::Render@@ -423,7 +432,12 @@ pub fn command_for(app: &SolveApp, key: &str) -> Option<&'static str> {&& solidcraft_engine::find_command(id).is_some_and(|c| crate::render_workspace::interactive_command_info(app, c).enabled)}).collect();- enabled.iter().find(|id| scope(id) == here).or(enabled.first()).copied()+ let mine = enabled.iter().find(|id| scope(id) == here);+ if app.preferences.sketch_keys_only && here != Scope::Render {+ mine.or_else(|| enabled.iter().find(|id| runs_everywhere(id))).copied()+ } else {+ mine.or(enabled.first()).copied()+ }}/// Run a shortcut key: its enabled command; outside a sketch, a sketch tool's key opens Create@@ -635,6 +649,8 @@ pub fn page(app: &mut SolveApp, ui: &mut egui::Ui) {action = Some((String::new(), chosen));}ui_kit::text(ui, app.tr_label("Select Other: hold the left button still on the model (or right-click › Select Other…) to list everything under the cursor; click again on the same spot to select the next thing there. Double-click the middle button to go Home (Preferences › Navigation)."), ui_kit::Text::Note("navigation"));+ ui_kit::checkbox(ui, app.tr("ui.sketch_keys_only"), &mut app.preferences.sketch_keys_only)+ .on_hover_text(app.tr("ui.sketch_keys_only_tip"));}// The list Help and Home open looks like the Shortcuts page of Preferences: say it can't// be changed here, and lead to the page where it can (#7409).diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rsindex 258860c977..7982ee332f 100644--- a/crates/ui-egui/src/prefs.rs+++ b/crates/ui-egui/src/prefs.rs@@ -1508,6 +1508,10 @@ preference_settings! {/// that component first, so the sketch belongs to it (`sketch.create` `activate_part`,/// #10215). Off (the default): the sketch belongs to the active component, as before.sketch_face_activates_part: bool = false, PAGE_SKETCH => check_id("prefs.sketch_face_activates_part");+ /// While a sketch is open, only sketch keys and keys that work everywhere run; a model+ /// command's key (E, F) does nothing. Off (the default): a model key pressed in a sketch+ /// runs its command, and one that builds a feature finishes the sketch first (#2815).+ sketch_keys_only: bool = false, PAGE_SHORTCUTS;/// Where the view goes when a sketch ends (#7038). Keep (the default) leaves it as it is.sketch_exit_view: SketchExitView = SketchExitView::default(), PAGE_SKETCH;/// A shape drawn in a sketch gets all its dimensions at once: the typed values, and everydiff --git a/crates/ui-egui/src/sketch_shortcut_tests.rs b/crates/ui-egui/src/sketch_shortcut_tests.rsindex 3a6aea6f41..1c17a906cb 100644--- a/crates/ui-egui/src/sketch_shortcut_tests.rs+++ b/crates/ui-egui/src/sketch_shortcut_tests.rs@@ -219,6 +219,33 @@ fn move_key_keeps_sketch_mode_behavior_and_honors_a_sketch_move_binding() {assert!(h.app.tree.occurrence_move.is_none(), "M must not open component Move while editing its sketch");}+/// With Keep model keys out of sketches on, sketches and the model have their own keys: with M+/// bound to Move/Copy Sketch Entities too, M is Move outside a sketch and Move/Copy Sketch+/// Entities in one; F (Fillet) does nothing in a sketch; Measure's key works in both; and a key+/// only clashes with commands that work in the same place.+#[test]+fn sketch_and_model_keys_are_kept_apart() {+ use crate::keymap::{Scope, bind, command_for, scope};+ let mut h = Harness::new();+ h.app.preferences.sketch_keys_only = true;+ assert_eq!(scope("sketch.move"), Scope::Sketch);+ assert_eq!(scope("solid.fillet"), Scope::Model);+ bind(&mut h.app, "sketch.move", "M", false).unwrap();+ assert_eq!(command_for(&h.app, "M"), Some("solid.move"));+ h.app.run("sketch.create", json!({"plane": "XY"})).unwrap();+ h.settle();+ assert_eq!(command_for(&h.app, "M"), Some("sketch.move"));+ assert_eq!(command_for(&h.app, "F"), None, "no model tool from a key pressed in a sketch");+ press(&mut h, "F");+ assert!(h.app.dialog.is_none() && h.app.session.active_sketch.is_some(), "F left the sketch alone");+ assert_eq!(command_for(&h.app, "I"), Some("inspect.measure"), "Measure's key works in a sketch too");+ // A sketch command may take a model command's key, but not another sketch command's.+ bind(&mut h.app, "sketch.fillet", "F", false).unwrap();+ assert_eq!(command_for(&h.app, "F"), Some("sketch.fillet"));+ let e = bind(&mut h.app, "sketch.fillet", "L", false).unwrap_err();+ assert!(e.contains("already used"), "{e}");+}+/// #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]@@ -315,6 +342,21 @@ fn the_extrude_key_in_a_sketch_finishes_the_sketch() {assert!(matches!(h.app.dialog.as_ref().map(|d| &d.kind), Some(crate::dialogs::Kind::Extrude { .. })));}+/// With Keep model keys out of sketches on, E in a sketch does nothing: the sketch stays open and+/// no Extrude opens. Off (the default), the test above holds.+#[test]+fn with_model_keys_kept_out_the_extrude_key_in_a_sketch_does_nothing() {+ let mut h = Harness::new();+ h.app.preferences.sketch_keys_only = true;+ h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();+ let sketch = h.app.session.active_sketch;+ h.app.run("sketch.rectangle.two_point", json!({"p0":[0,0],"p1":[20,10]})).unwrap();+ press(&mut h, "E");+ assert_eq!(h.app.session.active_sketch, sketch, "E left the sketch open");+ assert!(h.app.dialog.is_none(), "no dialog opened: {:?}", h.app.dialog.as_ref().map(|d| &d.kind));+ assert!(h.app.tool.is_none());+}+#[test]fn a_construct_command_keeps_the_sketch_open() {let mut h = Harness::new();diff --git a/docs/book/src/guide/shortcuts.md b/docs/book/src/guide/shortcuts.mdindex 752c04542c..3e390c9500 100644--- a/docs/book/src/guide/shortcuts.md+++ b/docs/book/src/guide/shortcuts.md@@ -56,6 +56,15 @@ from then on. The choice is kept across designs and restarts. With **Pressing aagain switches its mode** on (Preferences › Sketch), pressing the key again before the firstclick steps to the family's next variant.+One key can be bound to a sketch tool and to a model command at once: in a sketch the key runs+the sketch tool, outside one the model command. Outside a sketch, a sketch tool's key opens+Create Sketch and starts the tool in the new sketch. By default a model command's key pressed+in a sketch still runs it, and one that builds a feature (E, Extrude) finishes the sketch first.+With **Keep model keys out of sketches** on (File › Keyboard Shortcuts), a sketch and the model+keep their keys apart: while editing a sketch only sketch keys and keys that work everywhere+(Measure, the views, the file commands) run, and a model key such as E or F does nothing, so a+stray key can't close a heavy sketch.+Keys handled by the window itself:| Key | Action |