Keys: option to keep model keys out of sketches (#7675)

* Keys: a sketch and the model kept apart on Scope

`command_for` fell back to the first enabled command bound to a key, so a model key pressed in
a sketch (F, Fillet) still ran the model command. A key now runs only a command of the scope
the view is in, or one that works everywhere; otherwise nothing fires. Inspecting, views and
file commands (`inspect.*`, `view.*`, `file.*`) count as everywhere, so Measure's I still works
in a sketch. #4432's `sketch_and_model_keys_are_kept_apart` is ported to `Scope`.

Not ready: main's `the_extrude_key_in_a_sketch_finishes_the_sketch` (#2815) expects E in a
sketch to finish it and open Extrude, which this rule stops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keys: keep model keys out of sketches as an opt-in preference

The strict sketch/model split is now Preferences > Shortcuts > Keep model
keys out of sketches, off by default. Off, a key resolves exactly as on
main (a feature key such as E still finishes the sketch). On, a sketch
runs only sketch keys and keys that work everywhere (inspect, view, file).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* rustfmt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dudedagger42
2026-11-02 19:24:51 +00:00
committed by GitHub
parent e4cae82274
commit 6be5be7f0c
5 changed files with 101 additions and 4 deletions
@@ -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 等模型快捷键不起作用,因此误按的按键不会关闭复杂的草图。"
}
}
+20 -4
View File
@@ -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).
+4
View File
@@ -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 every
@@ -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();
+9
View File
@@ -56,6 +56,15 @@ from then on. The choice is kept across designs and restarts. With **Pressing a
again switches its mode** on (Preferences › Sketch), pressing the key again before the first
click 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 |