From bdd5ae31c86b745ea38b85c4e2cc8278e8d99082 Mon Sep 17 00:00:00 2001 From: ancientastronauttheorist Date: Wed, 25 Nov 2026 22:28:37 -0600 Subject: [PATCH] Home screen: the rail's Home row and the Window menu's documents lead back to the document With a document open and the Home screen up, the rail's Home row fires `window.home`, which no menu item makes available, so the shortcut path refused it ("not available in the current state"). A `home` command source now runs it, as the options bar's Home button does. Choosing an open document in the Window menu now also leaves Home. With no document open both still do nothing. Fixes #16802. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Gr84Vw42Y1h9tPLDK7SFRm --- crates/ui-egui/src/app/framework.rs | 12 +++ .../ui-egui/src/home_screen_way_back_tests.rs | 76 +++++++++++++++++++ crates/ui-egui/src/lib.rs | 2 + crates/ui-egui/src/menus/invoke.rs | 2 + 4 files changed, 92 insertions(+) create mode 100644 crates/ui-egui/src/home_screen_way_back_tests.rs diff --git a/crates/ui-egui/src/app/framework.rs b/crates/ui-egui/src/app/framework.rs index bfa6c349ae..92edb0349c 100644 --- a/crates/ui-egui/src/app/framework.rs +++ b/crates/ui-egui/src/app/framework.rs @@ -623,6 +623,8 @@ pub(crate) const COMMAND_SOURCES: &[CommandSource] = &[ CommandSource { name: "artboard", states: crate::artboard_tool::source_states, run: crate::artboard_tool::run_fired }, // Space+F: the pasteboard colour keys of the held Hand. CommandSource { name: "canvasColor", states: no_states, run: crate::canvas_tool_menu::run_canvas_color }, + // The Home screen rail's Home row fires `window.home` (#16802), which no menu item makes available. + CommandSource { name: "home", states: no_states, run: run_home }, // The options bar's engine-command buttons: their commands run through `shortcuts::handle`. CommandSource { name: "selection", states: crate::panels::options_bar::selection::source_states, run: |_, _, _| false }, ]; @@ -687,6 +689,16 @@ fn command_states(app: &PhotocraftApp, held: &mut HeldStates) { #[cfg(test)] mod catalog_tests; +/// `window.home`, fired by the Home screen rail's Home row: leaves Home for the open documents, as the options bar's +/// Home button does, and does nothing with no document open ([`crate::canvas::start_screen::toggle_home`]). +fn run_home(app: &mut PhotocraftApp, _ctx: &egui::Context, command: &CommandRef) -> bool { + if command.id != "window.home" { + return false; + } + crate::canvas::start_screen::toggle_home(app); + true +} + /// Selects the tool a tool command names. fn run_tool(app: &mut PhotocraftApp, _ctx: &egui::Context, command: &CommandRef) -> bool { let Some(command) = crate::panels::tool_commands::ToolCommand::from_ref(command) else { diff --git a/crates/ui-egui/src/home_screen_way_back_tests.rs b/crates/ui-egui/src/home_screen_way_back_tests.rs new file mode 100644 index 0000000000..d388522634 --- /dev/null +++ b/crates/ui-egui/src/home_screen_way_back_tests.rs @@ -0,0 +1,76 @@ +//! #16802: with a document open, the Home screen has a way back to it: the rail's Home row, and the document's entry +//! at the bottom of the Window menu. With no document open, Home has nothing behind it and both leave it up. + +use egui_kittest::Harness; +use egui_kittest::kittest::Queryable; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::app::framework::BuildApp as _; + +type H = Harness<'static, Box>; + +/// The app showing its document area (the Home screen while Home is up), with `documents` documents open. The app's +/// own frame runs around it, so a command the Home screen fires is run as in the app. +fn harness(documents: usize) -> H { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + for _ in 0..documents { + app.run("file.new", json!({"width": 64, "height": 64})).unwrap(); + } + let mut h = Harness::builder() + .with_size(egui::vec2(1100.0, 700.0)) + .with_max_steps(64) + .build_app(|ui, app: &mut PhotocraftApp| crate::canvas::document_area(app, ui), app); + h.run_steps(4); + h +} + +/// Whether the Home screen is up. +fn home(h: &mut H) -> bool { + h.state_mut().home_screen_up() +} + +/// The options bar's Home button: shows Home over the open documents. +fn show_home(h: &mut H) { + crate::canvas::start_screen::toggle_home(h.state_mut()); + h.run_steps(4); +} + +/// A click on the Home row of the Home screen's rail. +fn click_home_row(h: &mut H) { + h.get_by_label("Home").click(); + h.run_steps(4); +} + +#[test] +fn the_rails_home_row_returns_to_the_open_document() { + let mut h = harness(1); + show_home(&mut h); + assert!(home(&mut h), "Home is up over the document"); + let doc = h.state().session.active().map(|d| d.doc.id); + click_home_row(&mut h); + assert!(!home(&mut h), "the Home row leaves Home: {}", h.state().ui.status); + assert_eq!(h.state().session.active().map(|d| d.doc.id), doc, "back on the same document, unchanged"); + assert_eq!(h.state().session.documents().len(), 1); +} + +#[test] +fn choosing_an_open_document_in_the_window_menu_leaves_home() { + let mut h = harness(2); + let first = h.state().session.documents()[0].doc.id; + show_home(&mut h); + assert!(home(&mut h)); + let ctx = h.ctx.clone(); + crate::menus::invoke(h.state_mut(), &ctx, "window.document.0", json!({})).unwrap(); + h.run_steps(4); + assert!(!home(&mut h), "choosing the document leaves Home"); + assert_eq!(h.state().session.active().map(|d| d.doc.id), Some(first), "and shows that document"); +} + +#[test] +fn with_no_document_open_home_stays_up() { + let mut h = harness(0); + assert!(home(&mut h), "Home is all there is with no document"); + click_home_row(&mut h); + assert!(home(&mut h), "the Home row has nothing to return to"); +} diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 20d0f0d1ca..dbb16fff02 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -1096,6 +1096,8 @@ mod selection_move_step_tests; #[cfg(test)] mod view_guides_submenu_tests; +#[cfg(test)] +mod home_screen_way_back_tests; #[cfg(test)] mod lasso_click_tests; #[cfg(test)] diff --git a/crates/ui-egui/src/menus/invoke.rs b/crates/ui-egui/src/menus/invoke.rs index 2d01f0df91..2516e4cc80 100644 --- a/crates/ui-egui/src/menus/invoke.rs +++ b/crates/ui-egui/src/menus/invoke.rs @@ -862,6 +862,8 @@ fn invoke_window_command(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str, id.strip_prefix(DOCUMENT_ITEM).ok_or("no such document")?.parse::().ok().filter(|index| *index < count).ok_or("no such document")?; app.session.set_active(next); app.jobs.focus = None; + // Choosing a document shows it, so it leaves the Home screen opened over the documents (#16802). + app.ui.chrome.home = None; Ok(json!({"document": next})) })()), _ => None,