From 9cd83e93424595c31bc41457aa5b8cd78f916be1 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 14:28:23 -0800 Subject: [PATCH] Learn: a click or Enter on the skill or tutorial opened before opens it again Follow-up to #8800. The Learn panel's skill and tutorial lists keep their selection, and a click on the row that is already selected reports CollectionEvent::Picked rather than a selection change, so after Back a click on the skill or tutorial opened before did nothing. Enter on that row reports Activate, which the lists also ignored. The lists now open the item on Picked and Activate as well as on a selection change, as every row click did before the port. --- crates/ui-egui/src/panels/learn.rs | 6 +-- crates/ui-egui/src/panels/learn/tests.rs | 49 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/panels/learn.rs b/crates/ui-egui/src/panels/learn.rs index d765fe48c3..985871889c 100644 --- a/crates/ui-egui/src/panels/learn.rs +++ b/crates/ui-egui/src/panels/learn.rs @@ -73,10 +73,12 @@ fn run(app: &mut VectorcraftApp, cmd: &str, params: Value) { } } -/// The key a collection's last selection change set, if any: a click on a row or a tab. +/// The key a collection's last pick chose, if any: a click on a row or a tab, a click on the row or tab already +/// selected, or Enter on one. fn picked(events: Vec>) -> Option { events.into_iter().rev().find_map(|event| match event { CollectionEvent::Selection { change: SelectionChange::Set(keys), .. } => keys.into_iter().last(), + CollectionEvent::Picked { key, .. } | CollectionEvent::Activate(key) => Some(key), _ => None, }) } @@ -158,8 +160,6 @@ fn skill_list(app: &mut VectorcraftApp, ui: &mut Ui) { let rings: Vec<(&'static catalog::Skill, SkillRing)> = catalog::SKILLS.iter().map(|s| (s, SkillRing { done: progress.done(s), total: s.tutorials.len() })).collect(); let source = keyed(&keys, |key: &&'static str| *key); - // PLAN: a single-select list keeps its last pick highlighted and reports no change when the same key is - // picked again; the keys differ between the levels, but the list is the framework's to reset on a new view. // A few skills: the list is as tall as its rows, so Reset progress shows under them. let out = List::new(tl!("Skills")).select(SelectMode::Single).natural_height(true).show_items(ui, &source, &mut |key, _| { let row = ListRow::new(*key); diff --git a/crates/ui-egui/src/panels/learn/tests.rs b/crates/ui-egui/src/panels/learn/tests.rs index 78a2c12e08..d47f6a39b9 100644 --- a/crates/ui-egui/src/panels/learn/tests.rs +++ b/crates/ui-egui/src/panels/learn/tests.rs @@ -400,6 +400,55 @@ fn the_tabs_rows_and_back_run_their_commands() { press(&mut app, "Back", View { tab: Tab::Skills, skill: None, tutorial: None }); } +/// A click on the skill or the tutorial that was opened before, after Back, opens it again. +#[test] +fn a_click_on_the_skill_or_tutorial_opened_before_opens_it_again() { + let mut app = app(); + let ctx = app.ui_ctx.clone().expect("a window"); + let (skill, tutorial) = catalog::tutorial("gradient").unwrap(); + let open_skill = View { tab: Tab::Skills, skill: Some(skill.id), tutorial: None }; + let open_tutorial = View { tutorial: Some(tutorial.id), ..open_skill.clone() }; + let skills = View { tab: Tab::Skills, skill: None, tutorial: None }; + for (name, view) in [ + ("Skills", skills.clone()), + (skill.title, open_skill.clone()), + (tutorial.title, open_tutorial.clone()), + ("Back", open_skill.clone()), + (tutorial.title, open_tutorial.clone()), + ("Back", open_skill.clone()), + ("Back", skills.clone()), + (skill.title, open_skill.clone()), + ] { + click(&mut app, &ctx, name, show); + assert_eq!(app.ui.learn, view, "{name}"); + } +} + +/// Enter on the tutorial that was opened before, after Back and Tab into the list, opens it again. +#[test] +fn enter_on_the_tutorial_opened_before_opens_it_again() { + let mut app = app(); + let ctx = app.ui_ctx.clone().expect("a window"); + let (_, tutorial) = catalog::tutorial("gradient").unwrap(); + app.run("learn.show", json!({"tutorial": tutorial.id})).unwrap(); + let opened = app.ui.learn.clone(); + let key = |key| egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }; + click(&mut app, &ctx, "Back", show); + click(&mut app, &ctx, tutorial.title, show); + assert_eq!(app.ui.learn, opened, "a click opens it"); + click(&mut app, &ctx, "Back", show); + let focused = |app: &mut VectorcraftApp, events| { + let input = egui::RawInput { events, screen_rect: Some(SCREEN), ..Default::default() }; + let update = crate::testing::part_frame(app, &ctx, input, show).platform_output.accesskit_update?; + update.nodes.into_iter().find(|(id, _)| *id == update.focus).and_then(|(_, n)| n.label().map(str::to_owned)) + }; + let on_row = (0..10).any(|_| focused(&mut app, vec![key(egui::Key::Tab)]).as_deref() == Some(tutorial.title)); + assert!(on_row, "Tab reaches the tutorial's row"); + frame(&mut app, &ctx, vec![key(egui::Key::Enter)], show); + frame(&mut app, &ctx, vec![], show); + assert_eq!(app.ui.learn, opened, "Enter opens it"); +} + /// `learn.tab` switches tabs and keeps what the Skills tab had open; `learn.skill` opens a skill's /// tutorials and answers the skill as `learn.list` lists it; `learn.back` goes up one level and /// keeps the view on the list of skills and on the For you tab.