From 66be7fbcd2fb54aab922a763d613e01f3c0d8cf9 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Sat, 7 Nov 2026 08:16:09 -0800 Subject: [PATCH] Ignore the Behind shortcut without an active document --- crates/ui-egui/src/brush_behind_key_tests.rs | 21 ++++++++++++++++++++ crates/ui-egui/src/input/blend_keys.rs | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/brush_behind_key_tests.rs b/crates/ui-egui/src/brush_behind_key_tests.rs index 2ea48364b3..36e88fb6a4 100644 --- a/crates/ui-egui/src/brush_behind_key_tests.rs +++ b/crates/ui-egui/src/brush_behind_key_tests.rs @@ -68,6 +68,27 @@ fn brush_and_pencil_select_behind_in_one_command() { } } +/// A shortcut on the start screen must leave both the live brush and its owning tool alone. +#[test] +fn brush_and_pencil_do_not_select_behind_without_a_document() { + for (tool, brush_tool) in [(Tool::Brush, Tool::Pencil), (Tool::Pencil, Tool::Brush)] { + let mut app = PhotocraftApp::new(Session::new(), Default::default()); + assert!(app.session.active().is_none()); + app.ui.tool = tool; + app.ui.brush_tool = brush_tool; + app.ui.tool_options.brush_clear = true; + app.ui.tool_options.pencil_clear = true; + app.session.tools.brush.mode = BlendMode::Multiply; + let brush = app.session.execute("brush.get", json!({})).unwrap(); + let before = app.session.journal.len(); + press_behind(&mut app, &Context::default()); + assert_eq!(app.session.journal.len(), before); + assert_eq!(app.session.execute("brush.get", json!({})).unwrap(), brush); + assert_eq!(app.ui.brush_tool, brush_tool); + assert!(app.ui.tool_options.brush_clear && app.ui.tool_options.pencil_clear); + } +} + /// The same Background restriction used by the menu applies before the shortcut changes settings. #[test] fn background_does_not_accept_behind() { diff --git a/crates/ui-egui/src/input/blend_keys.rs b/crates/ui-egui/src/input/blend_keys.rs index 3ad0e8f9df..fb3d5d47b5 100644 --- a/crates/ui-egui/src/input/blend_keys.rs +++ b/crates/ui-egui/src/input/blend_keys.rs @@ -267,7 +267,7 @@ pub fn pick_mode(app: &mut PhotocraftApp, pick: Pick) { Pick::Behind => { let item = crate::brush_mode_menu::Item::Behind; let tool = app.ui.tool; - if !crate::brush_mode_menu::enabled(app, item) { + if app.session.active().is_none() || !crate::brush_mode_menu::enabled(app, item) { return; } let Some((id, params)) = crate::brush_mode_menu::engine_call(app, tool, item) else { return };