Edit Extrude: close on the first Escape (#9084) (#9757)

* claim: #9084

* Edit Extrude: close on the first Escape (#9084)

An edit dialog whose value names a parameter (`T` in Edit Extrude) opened with
that field focused and its completion list showing the longer names (`tan(`),
unarmed. The list took the first Escape, so the dialog needed two.

An unarmed list now leaves Escape to the window until the box is typed in, as
it already leaves Enter and Tab; once typed in, Escape dismisses the list first
as before. Its hint drops "Esc dismiss" in that state.

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:
froglemonade2
2026-11-01 18:02:39 +00:00
committed by GitHub
parent 2014e60ae6
commit 3ccf04d4b2
3 changed files with 72 additions and 1 deletions
@@ -0,0 +1,9 @@
{
"ar": { "↑ ↓ choose · Enter applies this value": "↑ ↓ اختيار · Enter يطبّق هذه القيمة" },
"de": { "↑ ↓ choose · Enter applies this value": "↑ ↓ auswählen · Eingabe übernimmt diesen Wert" },
"en": { "↑ ↓ choose · Enter applies this value": "↑ ↓ choose · Enter applies this value" },
"he": { "↑ ↓ choose · Enter applies this value": "↑ ↓ בחירה · Enter מחיל את הערך הזה" },
"ja": { "↑ ↓ choose · Enter applies this value": "↑ ↓ 選択 · Enter この値を適用" },
"vi": { "↑ ↓ choose · Enter applies this value": "↑ ↓ để chọn · Enter để áp dụng giá trị này" },
"zh": { "↑ ↓ choose · Enter applies this value": "↑ ↓ 选择 · Enter 应用此值" }
}
+30
View File
@@ -6845,6 +6845,36 @@ mod refused_ok_tests {
}
}
/// One Escape closes an edit dialog opened from its History row, also when its value names a parameter
/// and the field lists the longer names (`T` lists `tan(`, #9084).
#[test]
fn one_escape_closes_an_edit_dialog_whose_value_names_a_parameter() {
for name in ["Plate", "Corners", "Hole"] {
let mut h = Harness::new();
for (command, params) in [
("parameters.add", json!({"name": "T", "expression": "3 mm"})),
("parameters.add", json!({"name": "R", "expression": "5 mm"})),
("sketch.create", json!({"plane": "XY"})),
("sketch.rectangle.two_point", json!({"p0": [-40, -25], "p1": [40, 25]})),
("sketch.finish", json!({})),
("solid.extrude", json!({"distance": "T", "name": "Plate"})),
("solid.fillet", json!({"edges": [[40, 25, 1.5], [-40, 25, 1.5]], "radius": "R", "name": "Corners"})),
("solid.hole", json!({"position": [0, 0, 3], "diameter": 3.4, "name": "Hole"})),
] {
h.app.run(command, params).unwrap();
}
h.frames(2);
steps(&mut h, &[json!({"click": {"handle": format!("timeline:{name}")}, "double": true}), json!({"frames": 30})]);
assert!(h.app.dialog.as_ref().is_some_and(|d| d.editing.is_some()), "{name}: the edit dialog opened");
if name != "Hole" {
assert!(h.ctx.memory(|m| m.focused()).is_some(), "{name}: its value field has the keyboard");
assert!(crate::expression_complete::popup_state(&h.ctx).is_some(), "{name}: the field lists longer names");
}
steps(&mut h, &[json!({"key": "Escape"}), json!({"frames": 2})]);
assert!(h.app.dialog.as_ref().is_none_or(|d| d.editing.is_none()), "{name}: one Escape closes the dialog");
}
}
fn set_depth(h: &mut Harness, depth: &str) {
steps(h, &[json!({"click": {"handle": "dialog:Depth"}}), json!({"key": "A", "cmd": true}), json!({"text": depth})]);
}
+33 -1
View File
@@ -35,6 +35,11 @@ struct Popup {
empty: bool,
/// Down arrow in the empty box opened it: every named parameter, however many (#9246).
every: bool,
/// The box was typed in since it took the focus. Until then an unarmed list only shows
/// what longer names there are, for a value the window filled in (`T` in Edit Extrude
/// lists `tan(`): Escape passes it by and closes the window as it would without the list,
/// as Enter and Tab do (#9084).
typed: bool,
}
fn popup_id() -> egui::Id {
@@ -105,6 +110,7 @@ pub(crate) fn begin_frame(ctx: &egui::Context) {
// Unarmed, the typed word is complete: Enter submits it and Tab moves on.
Key::Enter | Key::Tab if !popup.armed => continue,
Key::Enter | Key::Tab => popup.accept = true,
Key::Escape if !popup.armed && !popup.typed => continue,
Key::Escape => {
popup.dismissed = true;
popup.accept = false;
@@ -169,6 +175,7 @@ pub(crate) fn complete(ui: &mut egui::Ui, resp: &egui::Response, text: &mut Stri
// Dismissed suggestions stay closed until this box is typed in: another control rewriting
// its text (a slider dragged while the box keeps the focus) or a moved caret is no reason.
let dismissed = previous.as_ref().is_some_and(|p| p.dismissed) && !resp.changed();
let typed = resp.changed() || previous.as_ref().is_some_and(|p| p.typed);
// What the word follows, blanks aside.
let before = text.chars().take(start).filter(|c| !c.is_whitespace()).last();
// A word that is already a complete name opens unarmed: Enter submits it as typed. A unit is
@@ -191,7 +198,9 @@ pub(crate) fn complete(ui: &mut egui::Ui, resp: &egui::Response, text: &mut Stri
keyed: false,
empty: false,
every: false,
typed,
});
popup.typed = typed;
popup.empty = text.is_empty();
popup.armed = popup.keyed || armed;
// Never over a control being dragged: the drag dismisses them.
@@ -251,10 +260,13 @@ pub(crate) fn complete(ui: &mut egui::Ui, resp: &egui::Response, text: &mut Stri
popup.armed.then_some(popup.selected),
&options,
// Unarmed, the typed word is complete and Enter submits it; an arrow key arms the list.
// Escape is the window's until the box is typed in.
crate::i18n::tr_label(if popup.armed {
"↑ ↓ choose · Enter / Tab complete · Esc dismiss"
} else {
} else if popup.typed {
"↑ ↓ choose · Enter applies what you typed · Esc dismiss"
} else {
"↑ ↓ choose · Enter applies this value"
}),
) && pick.is_none()
&& !released_after_press
@@ -542,6 +554,26 @@ mod tests {
}
}
/// A list that opened by itself on a value the window filled in leaves Escape to the window
/// (#9084); once the box is typed in, Escape dismisses the list first.
#[test]
fn escape_passes_an_unarmed_list_until_the_box_is_typed_in() {
let mut e = Editor::new("width");
assert_eq!(e.popup().map(|(_, armed)| armed), Some(false));
e.key(Key::Escape);
assert!(e.leaked.contains(&Key::Escape));
assert!(!e.ctx.memory(|m| m.has_focus(e.id)));
let mut e = Editor::new("widt");
e.frame(vec![egui::Event::Text("h".into())]);
assert_eq!(e.text, "width");
assert_eq!(e.popup().map(|(_, armed)| armed), Some(false));
e.key(Key::Escape);
assert!(e.leaked.is_empty());
assert!(!showing(&e.ctx, e.id));
assert!(e.ctx.memory(|m| m.has_focus(e.id)));
}
/// From the unarmed popup an arrow key picks a row (Down the first, Up the last); Enter or
/// Tab then complete it as usual.
#[test]