From a3541ed1d4c75c7142d6b2ae6b540e7b954a3c4e Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Sat, 24 Oct 2026 00:37:34 +0300 Subject: [PATCH] Desktop: Escape in a modified game asks about saving; Escape in the question leaves The game's Escape is taken when it leaves: the question about unsaved edits, opened in the same frame, read the same key as its own Escape and closed at once, so Escape seemed to do nothing in a modified game. In the question Escape now goes on without saving (the owner's choice); Cancel stays to keep editing. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- apps/desktop/src/app.rs | 8 ++++++-- apps/desktop/src/game_view.rs | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 64e1ec5..129f74c 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ cargo run --release -p chesspenguin -- examples/classics.pgn | Where | Keys | | --- | --- | | Library | ↑/↓ select · Enter open · Ctrl+O add PGN · Ctrl+N new game · Ctrl+F search | -| Game | ←/→ move · ↑ end · ↓ start (also End/Home) · Shift+↑/↓ switch variation · F flip · L engine · Shift+A game analysis · Esc leave a preview, then back to the previous game or the library | +| Game | ←/→ move · ↑ end · ↓ start (also End/Home) · Shift+↑/↓ switch variation · F flip · L engine · Shift+A game analysis · Esc leave a preview, then back to the previous game or the library (unsaved edits: Esc again leaves without saving) | | Editing | Ctrl+Z / Ctrl+Y undo/redo · Ctrl+Shift+C copy PGN · Ctrl+S save as · Ctrl+W back to library | ## Project layout diff --git a/apps/desktop/src/app.rs b/apps/desktop/src/app.rs index ce49e6d..d6ff17d 100644 --- a/apps/desktop/src/app.rs +++ b/apps/desktop/src/app.rs @@ -761,10 +761,14 @@ impl App { if ui.button(tr("Save as…")).clicked() { choice = Some(0); } - if ui.button(tr("Don't save")).clicked() { + // Escape goes on where the user was going (the owner's choice): the + // second Escape of "Escape, Escape" leaves without saving. Cancel stays. + if ui.button(tr("Don't save")).on_hover_text("Esc").clicked() + || ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, Key::Escape)) + { choice = Some(1); } - if ui.button(tr("Cancel")).clicked() || ui.input(|i| i.key_pressed(Key::Escape)) { + if ui.button(tr("Cancel")).clicked() { choice = Some(2); } }); diff --git a/apps/desktop/src/game_view.rs b/apps/desktop/src/game_view.rs index 2cececa..e6abf74 100644 --- a/apps/desktop/src/game_view.rs +++ b/apps/desktop/src/game_view.rs @@ -1489,6 +1489,9 @@ impl GameView { } else if self.board.is_busy() { self.board.clear(); } else if !crate::app::overlay_open(ui.ctx()) { + // Taken: the question about unsaved edits that leaving may open in + // this frame must not read the same key as its own Escape. + ui.input_mut(|i| i.consume_key(Modifiers::NONE, Key::Escape)); actions.push(if self.previous.is_some() { GameAction::ReturnToPrevious } else {