Desktop: ↑ to the end, ↓ to the start, Escape leaves the game
Some checks are pending
CI / check (push) Waiting to run
CI / windows-build (push) Waiting to run
CI / macos-build (push) Waiting to run

Variations move to Shift+↑/↓. Escape cancels a preview or a picked-up piece first, then
returns to the previous game or the library; a window, menu or dialog open over the game
(this frame or the last) keeps the key. CP_KEYS presses keys for manual checks.
Also drops an empty database of a local site run committed by mistake.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-10-22 19:57:53 +03:00
parent 3cb6730692
commit 29ded2f55f
10 changed files with 123 additions and 10 deletions

View file

@ -25,6 +25,24 @@ enum Async {
EngineChecked(Result<(PathBuf, String), String>),
}
/// The id of the toast: a passing message, never in the way of the keyboard.
pub const TOAST: &str = "toast";
/// Something is open over the screen — a window, a menu, a dialog — in this frame or the
/// last one: Escape is meant for it (it closes itself), not for leaving the screen.
pub fn overlay_open(ctx: &egui::Context) -> bool {
let passive = [
egui::Id::new(TOAST),
egui::Id::new(crate::engine_offer::DOWNLOAD_INDICATOR),
];
ctx.memory(|m| m.areas().visible_layer_ids())
.iter()
.any(|l| {
matches!(l.order, egui::Order::Middle | egui::Order::Foreground)
&& !passive.contains(&l.id)
})
}
#[derive(Clone, Copy, PartialEq)]
enum CloseIntent {
BackToLibrary,
@ -80,7 +98,9 @@ pub struct App {
/// Dev-only startup automation for screenshots/manual QA (see docs/dev/desktop.md):
/// `CP_OPEN=<game index>` opens a game from the first database, `CP_PLY=<n>` steps
/// along the main line, `CP_ANALYZE=1` starts the engine, `CP_SETTINGS=1` opens settings (`=board`, `=about`: that tab),
/// `CP_REVIEW=1` starts the whole-game analysis (`=dialog` only opens its dialog).
/// `CP_REVIEW=1` starts the whole-game analysis (`=dialog` only opens its dialog),
/// `CP_KEYS="ArrowDown Shift+ArrowUp Escape"` presses these keys, one every half second
/// from the second second.
#[derive(Default)]
struct DebugStartup {
open: Option<usize>,
@ -92,6 +112,8 @@ struct DebugStartup {
screenshot_delay: f64,
screenshot_requested: bool,
open_settings: bool,
keys: std::collections::VecDeque<(Modifiers, Key)>,
next_key: f64,
}
impl DebugStartup {
@ -108,6 +130,18 @@ impl DebugStartup {
.unwrap_or(4.0),
screenshot_requested: false,
open_settings: false,
keys: std::env::var("CP_KEYS")
.unwrap_or_default()
.split_whitespace()
.filter_map(|k| {
let (shift, name) = match k.strip_prefix("Shift+") {
Some(name) => (Modifiers::SHIFT, name),
None => (Modifiers::NONE, k),
};
Key::from_name(name).map(|key| (shift, key))
})
.collect(),
next_key: 2.0,
}
}
}
@ -217,6 +251,29 @@ impl App {
self
}
fn debug_keys(&mut self, ctx: &egui::Context) {
if self.debug.keys.is_empty() {
return;
}
let now = ctx.input(|i| i.time);
if now >= self.debug.next_key
&& let Some((modifiers, key)) = self.debug.keys.pop_front()
{
self.debug.next_key = now + 0.5;
ctx.input_mut(|i| {
i.modifiers = modifiers;
i.events.push(egui::Event::Key {
key,
physical_key: None,
pressed: true,
repeat: false,
modifiers,
});
});
}
ctx.request_repaint_after(std::time::Duration::from_millis(50));
}
fn debug_screenshot(&mut self, ctx: &egui::Context) {
if self.debug.open_settings && ctx.input(|i| i.time) > 1.5 {
self.debug.open_settings = false;
@ -781,6 +838,7 @@ impl eframe::App for App {
}
self.offer_events(&ctx);
self.debug_step(&ctx);
self.debug_keys(&ctx);
self.debug_screenshot(&ctx);
self.analysis.poll();
@ -1064,7 +1122,7 @@ impl eframe::App for App {
if now > *until {
self.toast = None;
} else {
egui::Area::new(egui::Id::new("toast"))
egui::Area::new(egui::Id::new(TOAST))
.anchor(egui::Align2::CENTER_BOTTOM, egui::vec2(0.0, -24.0))
.order(egui::Order::Foreground)
.show(&ctx, |ui| {

View file

@ -43,6 +43,11 @@ impl BoardState {
self.drag = None;
self.promotion = None;
}
/// A piece is selected or dragged, or a promotion is being chosen.
pub fn is_busy(&self) -> bool {
self.selected.is_some() || self.drag.is_some() || self.promotion.is_some()
}
}
/// Pieces moving from one position to the next, as on Lichess (chessground): each piece

View file

@ -11,6 +11,9 @@ use crate::engine_download::{self, Download, Failure, Stage};
use crate::i18n::{tr, trf};
use crate::settings::Settings;
/// The id of the download indicator in the corner (it is never in the way of Escape).
pub const DOWNLOAD_INDICATOR: &str = "download_indicator";
/// What the user wanted to do when the engine turned out to be missing.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Pending {
@ -399,7 +402,7 @@ impl EngineOffer {
Some(_) => "⬇ Stockfish…".to_string(),
None => tr("⚠ Stockfish wasn't downloaded").to_string(),
};
egui::Area::new(egui::Id::new("download_indicator"))
egui::Area::new(egui::Id::new(DOWNLOAD_INDICATOR))
.anchor(egui::Align2::RIGHT_BOTTOM, vec2(-12.0, -12.0))
.order(egui::Order::Foreground)
.show(ctx, |ui| {

View file

@ -448,7 +448,11 @@ impl GameView {
ui.horizontal(|ui| {
if ui
.button(tr("⬅ Library"))
.on_hover_text(tr("Back to the game list (Ctrl+W)"))
.on_hover_text(if self.previous.is_some() {
tr("Back to the game list (Ctrl+W)")
} else {
tr("Back to the game list (Esc, Ctrl+W)")
})
.clicked()
{
actions.push(GameAction::Back);
@ -456,7 +460,7 @@ impl GameView {
if let Some(t) = &self.previous
&& ui
.button(trf("⬅ Back to {game}", &[("game", t)]))
.on_hover_text(tr("The game this one was opened from, as you left it"))
.on_hover_text(tr("The game this one was opened from, as you left it (Esc)"))
.clicked()
{
actions.push(GameAction::ReturnToPrevious);
@ -1403,12 +1407,18 @@ impl GameView {
if i.consume_shortcut(&KeyboardShortcut::new(Modifiers::SHIFT, Key::A)) {
cmds.push("review");
}
if i.consume_shortcut(&KeyboardShortcut::new(Modifiers::SHIFT, Key::ArrowUp)) {
cmds.push("prev_var");
}
if i.consume_shortcut(&KeyboardShortcut::new(Modifiers::SHIFT, Key::ArrowDown)) {
cmds.push("next_var");
}
if i.modifiers.is_none() {
for (key, cmd) in [
(Key::ArrowLeft, "back1"),
(Key::ArrowRight, "fwd1"),
(Key::ArrowUp, "prev_var"),
(Key::ArrowDown, "next_var"),
(Key::ArrowUp, "end"),
(Key::ArrowDown, "home"),
(Key::Home, "home"),
(Key::End, "end"),
(Key::F, "flip"),
@ -1469,11 +1479,21 @@ impl GameView {
self.review.dialog_open = true;
}
}
// Escape cancels what is going on first (a preview of an engine line, a
// piece picked up); then it leaves the game: to the game this one was
// opened from, or to the library. A window, menu or dialog open over the
// game takes the key itself.
"esc" => {
if self.preview.is_some() {
self.preview = None;
} else {
} else if self.board.is_busy() {
self.board.clear();
} else if !crate::app::overlay_open(ui.ctx()) {
actions.push(if self.previous.is_some() {
GameAction::ReturnToPrevious
} else {
GameAction::Back
});
}
}
_ => {}

View file

@ -3401,6 +3401,14 @@ const ROWS: &[[&str; 6]] = &[
"La partida desde la que se abrió esta, tal como la dejaste",
"La partita da cui è stata aperta questa, come l'hai lasciata",
],
[
"The game this one was opened from, as you left it (Esc)",
"Партия, из которой открыта эта, — в том виде, как вы её оставили (Esc)",
"La partie d'où celle-ci a été ouverte, telle que vous l'avez laissée (Esc)",
"Die Partie, aus der diese geöffnet wurde, so wie Sie sie verlassen haben (Esc)",
"La partida desde la que se abrió esta, tal como la dejaste (Esc)",
"La partita da cui è stata aperta questa, come l'hai lasciata (Esc)",
],
[
"⬅ Back to {game}",
"⬅ К партии {game}",
@ -4841,6 +4849,14 @@ const ROWS: &[[&str; 6]] = &[
"Volver a la lista de partidas (Ctrl+W)",
"Torna all'elenco delle partite (Ctrl+W)",
],
[
"Back to the game list (Esc, Ctrl+W)",
"Вернуться к списку партий (Esc, Ctrl+W)",
"Retour à la liste des parties (Esc, Ctrl+W)",
"Zurück zur Partienliste (Esc, Ctrl+W)",
"Volver a la lista de partidas (Esc, Ctrl+W)",
"Torna all'elenco delle partite (Esc, Ctrl+W)",
],
[
"PGN compatibility notes",
"Замечания по совместимости PGN",