diff --git a/crates/ui-egui/src/app/framework.rs b/crates/ui-egui/src/app/framework.rs index 92edb0349c..bfa6c349ae 100644 --- a/crates/ui-egui/src/app/framework.rs +++ b/crates/ui-egui/src/app/framework.rs @@ -623,8 +623,6 @@ 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 }, ]; @@ -689,16 +687,6 @@ 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 index d388522634..14c295b2b4 100644 --- a/crates/ui-egui/src/home_screen_way_back_tests.rs +++ b/crates/ui-egui/src/home_screen_way_back_tests.rs @@ -47,11 +47,18 @@ 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); + let (doc, open) = (h.state().session.active().map(|d| d.doc.id), h.state().session.documents().len()); 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); + assert_eq!(h.state().session.active().map(|d| d.doc.id), doc, "back on the same document"); + assert_eq!(h.state().session.documents().len(), open, "nothing opened or closed"); +} + +/// Chooses Window menu item `id`, through the gate a menu click passes (its enabled state included). +fn choose(h: &mut H, id: &str) { + let ctx = h.ctx.clone(); + crate::shortcut_dispatch::dispatch(h.state_mut(), &ctx, id); + h.run_steps(4); } #[test] @@ -60,13 +67,23 @@ fn choosing_an_open_document_in_the_window_menu_leaves_home() { 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"); + choose(&mut h, "window.document.0"); + assert!(!home(&mut h), "choosing the document leaves Home: {}", h.state().ui.status); assert_eq!(h.state().session.active().map(|d| d.doc.id), Some(first), "and shows that document"); } +#[test] +fn next_and_previous_document_leave_home() { + for id in ["window.nextDocument", "window.previousDocument"] { + let mut h = harness(2); + let before = h.state().session.active().map(|d| d.doc.id); + show_home(&mut h); + choose(&mut h, id); + assert!(!home(&mut h), "{id} leaves Home: {}", h.state().ui.status); + assert_ne!(h.state().session.active().map(|d| d.doc.id), before, "{id} shows the other document"); + } +} + #[test] fn with_no_document_open_home_stays_up() { let mut h = harness(0); diff --git a/crates/ui-egui/src/menus/invoke.rs b/crates/ui-egui/src/menus/invoke.rs index 2516e4cc80..5433e179fd 100644 --- a/crates/ui-egui/src/menus/invoke.rs +++ b/crates/ui-egui/src/menus/invoke.rs @@ -854,6 +854,8 @@ fn invoke_window_command(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str, app.run("document.activate", json!({"document": next}))?; } app.jobs.focus = None; + // Next and Previous Document show the document they choose, so they leave Home too (#16802). + app.ui.chrome.home = None; Ok(json!({"document": next})) })()), _ if id.starts_with(DOCUMENT_ITEM) => Some((|| { diff --git a/crates/ui-egui/src/menus/state.rs b/crates/ui-egui/src/menus/state.rs index bf3cd0c253..9bc271b779 100644 --- a/crates/ui-egui/src/menus/state.rs +++ b/crates/ui-egui/src/menus/state.rs @@ -84,6 +84,9 @@ pub fn is_enabled(app: &PhotocraftApp, id: &str) -> bool { "window.togglePanels" => true, // With one document open the key stays quiet, as in Photoshop, rather than reporting why. "window.nextDocument" | "window.previousDocument" => app.session.active().is_some(), + // Home over the open documents, or back to them (the Home rail's Home row fires it, #16802). With no document + // open there is nothing behind Home. + "window.home" => !app.session.documents().is_empty(), i if panel_alias(i).is_some() || workspace_id(i).is_some() => true, i if proof_preset(i).is_some() => app.session.active().is_some(), // "Custom…" is the full Proof Setup dialog.