Esc leaves the sketch from the state you are actually left in

exussum12 on PR #15238: "Esc hardly ever works". He was right, and the word
that matters is "hardly" — it works while you are mid-entity and stops working
the moment you finish one.

The branch asked whether a DRAW TOOL was armed, not whether a SKETCH SESSION
was open:

    if (key == WXK_ESCAPE && m_viewport && m_viewport->is_sketching())

is_sketching() is DesignSketchTool::is_active(), true only between arming a
tool and finishing with it. Commit an entity and you are left at
ui_mode=Sketch with no tool armed, and from there Esc did nothing at all, no
matter how many times you pressed it — the Cancel button was the only way out.
Reproduced on the headless rig with SNAPORCA_KEYTRACE, which is what settled
it rather than reading: the key ARRIVES and focus is fine,

    [KEYTRACE] key=27 ui_mode=1 is_sketching=0 in_text=0 inline_busy=0 focus=w

so this was never the focus problem it looks like from the outside.

Gate on the session instead. request_exit() is already layered — abort the
in-progress entity, else drop the tool to Select, else exit to Feature — so
widening the gate adds no new behaviour, it just lets the ladder be reached
from its own last rung. is_sketching() stays in the condition as an OR, so
nothing about the armed-tool path changes.

This is the same mistake snaporca-0ud fixed thirty lines above in the same
handler, where gating the sketch key MAP on is_sketching() made all 17 keys
read as dead. The comment there now has a sibling.

VERIFIED ON THE RIG, before and after, same sequence (Design > XY > Shift+S >
click canvas): before, two Escapes left the toolbar on SKETCH with zero pixels
changed; after, the toolbar reads FEATURES — one Esc drops the armed tool to
Select, the second exits the session.

Kernel suite green, 2568 assertions in 191 test cases. libslic3r_gui builds
clean on both forks. Parity 17 identical / 8 diverging as expected.
This commit is contained in:
Tommaso Bianchi
2026-08-29 08:52:21 +02:00
parent 8f014de84c
commit 884a382a48
+10 -1
View File
@@ -4177,7 +4177,16 @@ DesignPanel::DesignPanel(wxWindow* parent)
// accident of where the user last clicked (a toolbar button, the Construction checkbox),
// and Esc must not depend on it — request_exit() is the layered behaviour the GL-canvas
// path already uses, so Esc means the same thing here as it does over the viewport.
if (key == WXK_ESCAPE && m_viewport && m_viewport->is_sketching()) {
// The predicate is the SESSION, not the armed tool. is_sketching() is
// DesignSketchTool::is_active(), true only while a draw tool is armed, and the state you
// are left in after committing an entity is ui_mode=Sketch with no tool armed -- so this
// branch used to be skipped exactly when a user reaches for Esc, and the Cancel button
// was the only way out ("Esc hardly ever works", exussum12 on PR #15238). Same mistake as
// snaporca-0ud, which gated the sketch key MAP on is_sketching() thirty lines above.
// request_exit() is layered and already handles the idle case, so widening the gate
// costs nothing: in-progress entity -> drop to Select -> exit the session.
if (key == WXK_ESCAPE && m_viewport
&& (m_ui_mode == UiMode::Sketch || m_viewport->is_sketching())) {
m_viewport->request_sketch_exit();
return;
}