Sketch keys: a variant with its own key leaves its family's key alone (#6289)
With G bound to the centre rectangle, G, Escape, R started the centre rectangle again, because R's family remembered the variant used last (#4308). A remembered variant that has a key of its own no longer takes over the family's key; one without a key still comes back on it. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -373,15 +373,24 @@ pub fn press(app: &mut SolveApp, key: &str, repeat: bool) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
app.start(app.preferences.sketch_variants.resolve(id));
|
||||
app.start(variant_for_key(app, id));
|
||||
} else if let Some(id) = sketch_tool_for(app, key) {
|
||||
let then = variant_for_key(app, id);
|
||||
app.start("sketch.create");
|
||||
if let Some(d) = app.dialog.as_mut().filter(|d| matches!(d.kind, crate::dialogs::Kind::Sketch)) {
|
||||
d.then_start = Some(app.preferences.sketch_variants.resolve(id));
|
||||
d.then_start = Some(then);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// What a family's key starts: the variant used last (#4308), unless that variant has a key of
|
||||
/// its own; then the family's key starts the command it is bound to, and the other key the
|
||||
/// variant.
|
||||
fn variant_for_key(app: &SolveApp, id: &'static str) -> &'static str {
|
||||
let chosen = app.preferences.sketch_variants.resolve(id);
|
||||
if chosen != id && effective(app, chosen).is_some() { id } else { chosen }
|
||||
}
|
||||
|
||||
/// Outside a sketch: the SKETCH-tab command bound to `key` that a new sketch would start. Not
|
||||
/// Normal/Construction (a mode of the drawing in progress) nor the Finish Sketch panel.
|
||||
fn sketch_tool_for(app: &SolveApp, key: &str) -> Option<&'static str> {
|
||||
|
||||
@@ -216,6 +216,28 @@ fn a_tools_shortcut_pressed_again_restarts_it_by_default() {
|
||||
assert_eq!(tool(&h), Some("sketch.rectangle.two_point"), "the same mode again");
|
||||
}
|
||||
|
||||
/// A variant with a key of its own doesn't take over its family's key: with G bound to the
|
||||
/// centre rectangle, G then Escape then R starts the corner rectangle R is bound to. A variant
|
||||
/// without a key still comes back on R (#4308).
|
||||
#[test]
|
||||
fn a_variant_with_its_own_key_leaves_the_family_key_alone() {
|
||||
let mut h = Harness::new();
|
||||
h.app.run("sketch.create", json!({"plane": "XY"})).unwrap();
|
||||
h.settle();
|
||||
crate::keymap::bind(&mut h.app, "sketch.rectangle.center", "G", true).unwrap();
|
||||
press(&mut h, "G");
|
||||
assert_eq!(tool(&h), Some("sketch.rectangle.center"));
|
||||
press(&mut h, "Escape");
|
||||
press(&mut h, "R");
|
||||
assert_eq!(tool(&h), Some("sketch.rectangle.two_point"), "R starts what it is bound to");
|
||||
press(&mut h, "Escape");
|
||||
h.app.start("sketch.rectangle.three_point");
|
||||
h.settle();
|
||||
press(&mut h, "Escape");
|
||||
press(&mut h, "R");
|
||||
assert_eq!(tool(&h), Some("sketch.rectangle.three_point"), "a variant without a key comes back on R");
|
||||
}
|
||||
|
||||
/// #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.
|
||||
|
||||
Reference in New Issue
Block a user