From ebd705cf5decac465076f2dea4b4205888641214 Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Fri, 27 Nov 2026 02:10:00 +0300 Subject: [PATCH] opening trainer: the branch header names the branch in SAN with move numbers (also from the QA hook) --- apps/desktop/src/opening_layout.rs | 19 +++++++++++++++++++ apps/desktop/src/opening_lines.rs | 16 +--------------- apps/desktop/src/repertoire_ui.rs | 11 ++++++++++- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/apps/desktop/src/opening_layout.rs b/apps/desktop/src/opening_layout.rs index ffadbed..c7da68b 100644 --- a/apps/desktop/src/opening_layout.rs +++ b/apps/desktop/src/opening_layout.rs @@ -203,6 +203,25 @@ pub(crate) fn move_text(game: &Game, node: NodeId) -> Option { }) } +/// "1. e4 e5 2. Nf3": the moves from the start to `node` with move numbers. +pub(crate) fn path_text(game: &Game, node: NodeId) -> String { + let mut words = Vec::new(); + for id in game.path(node).into_iter().skip(1) { + let Some(mv) = game.game_move(id) else { + continue; + }; + let san = crate::san::show(&mv.san).into_owned(); + match game.move_number(id) { + Some((number, Color::White)) => words.push(format!("{number}. {san}")), + Some((number, Color::Black)) if words.is_empty() => { + words.push(format!("{number}… {san}")) + } + _ => words.push(san), + } + } + words.join(" ") +} + /// The symbol of a move's assessment (`!`, `?!` …) and its colour for text. pub(crate) fn assessment(game: &Game, node: NodeId, dark: bool) -> Option<(&'static str, Color32)> { let nag = game diff --git a/apps/desktop/src/opening_lines.rs b/apps/desktop/src/opening_lines.rs index 2f9fb60..01fe24c 100644 --- a/apps/desktop/src/opening_lines.rs +++ b/apps/desktop/src/opening_lines.rs @@ -252,21 +252,7 @@ impl OpeningLinesUi { /// "… 4. Ba4 Nf6": the moves to a node in the notation of the application. fn path_label(&self, node: NodeId) -> String { - let mut words = Vec::new(); - for id in self.game.path(node).into_iter().skip(1) { - let Some(mv) = self.game.game_move(id) else { - continue; - }; - let san = crate::san::show(&mv.san).into_owned(); - match self.game.move_number(id) { - Some((number, Color::White)) => words.push(format!("{number}. {san}")), - Some((number, Color::Black)) if words.is_empty() => { - words.push(format!("{number}… {san}")) - } - _ => words.push(san), - } - } - words.join(" ") + layout::path_text(&self.game, node) } fn below(&self, path: &[String]) -> Option<(usize, usize, usize)> { diff --git a/apps/desktop/src/repertoire_ui.rs b/apps/desktop/src/repertoire_ui.rs index c2aadfa..9186520 100644 --- a/apps/desktop/src/repertoire_ui.rs +++ b/apps/desktop/src/repertoire_ui.rs @@ -2231,7 +2231,16 @@ impl RepertoireUi { .split_whitespace() .map(str::to_owned) .collect(); - let label = through.join(" "); + // The label in the notation of the application, as «Lines» gives it. + let label = self + .selected + .as_ref() + .and_then(|id| self.library.repertoire(id)) + .map(|r| r.game()) + .and_then(|game| { + layout::node_at(&game, &through).map(|at| layout::path_text(&game, at)) + }) + .unwrap_or_else(|| through.join(" ")); self.start(SessionKind::Branch { through, label }, settings); } "menu" => self.debug_menu = true,