Escape stays in the sketch (#1804) (#1836)

Thanks @thodoristsagko.
This commit is contained in:
Thodoris Tsagkogeorgas authored and GitHub committed 2026-10-17 04:07:26 -04:00
1 parent 337564190b
commit f3b5846e6b
2 files changed
+25 -3

No files matched your search

@@ -67,6 +67,29 @@ fn a_sketch_key_with_nothing_selected_asks_for_the_plane_then_starts_the_tool()
assert!(h.app.dialog.is_none()); assert!(h.app.dialog.is_none());
} }
/// #1804: Escape puts down the sketch tool. Another Escape does not leave the sketch.
#[test]
fn a_second_escape_stays_in_the_sketch() {
let mut h = Harness::new();
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
let sketch = h.app.session.active_sketch;
h.app.start("sketch.line");
h.settle();
assert_eq!(tool(&h), Some("sketch.line"));
press(&mut h, "Escape");
assert!(tool(&h).is_none(), "the first Escape puts the tool down");
assert_eq!(h.app.session.active_sketch, sketch);
press(&mut h, "Escape");
assert_eq!(h.app.session.active_sketch, sketch, "a second Escape stays in the sketch");
h.app.run("sketch.line", json!({"points":[[0,0],[10,0]]})).unwrap();
h.app.session.selection = vec![Sel::SketchCurve { id: "l1".into() }];
press(&mut h, "Escape");
assert!(h.app.session.selection.is_empty(), "Escape still clears a selection");
assert_eq!(h.app.session.active_sketch, sketch);
press(&mut h, "Escape");
assert_eq!(h.app.session.active_sketch, sketch, "Escape after clearing the selection stays in the sketch");
}
#[test] #[test]
fn escape_drops_the_tool_waiting_for_a_sketch() { fn escape_drops_the_tool_waiting_for_a_sketch() {
let mut h = Harness::new(); let mut h = Harness::new();
+2 -3
View File
@@ -1320,10 +1320,9 @@ pub fn shortcuts(app: &mut SolveApp, ctx: &egui::Context) {
} else if !app.session.selection.is_empty() || app.session.active_sketch.is_none() { } else if !app.session.selection.is_empty() || app.session.active_sketch.is_none() {
app.tree.picked_joints.clear(); app.tree.picked_joints.clear();
let _ = app.run("select.clear", json!({})); let _ = app.run("select.clear", json!({}));
} else {
// Nothing left to cancel: Esc finishes the sketch.
app.finish_sketch();
} }
// An open sketch with nothing left to cancel stays open (#1804). Finish Sketch
// is what leaves it, so a second Escape after putting a tool down is harmless.
} }
Key::S if !mods.shift && !mods.alt => { Key::S if !mods.shift && !mods.alt => {
let at = ctx.input(|i| i.pointer.latest_pos()); let at = ctx.input(|i| i.pointer.latest_pos());