PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge PR #6227: Separate shortcut capture checks from native snapshot rendering
aiongg35a6222e3593
diff --cc crates/ui-egui/src/shortcut_capture_tests.rsindex d48681ad6,57f7caee9..c7853067a--- a/crates/ui-egui/src/shortcut_capture_tests.rs+++ b/crates/ui-egui/src/shortcut_capture_tests.rs@@@ -13,19 -13,15 +13,25 @@@ fn key(h: &mut Harness<'_, PhotocraftAph.event(Event::Key { key, physical_key: None, pressed, repeat: false, modifiers });}+fn input_state(events: Vec<Event>, modifiers: Modifiers) -> egui::InputState {+ let ctx = egui::Context::default();+ ctx.begin_pass(egui::RawInput { events, ..Default::default() });+ let state = ctx.input(|i| i.clone());+ ctx.end_pass().textures_delta.clear();+ let mut state = state;+ state.modifiers = modifiers;+ state+}+/// The Keyboard Shortcuts dialog with `command` selected, filtered to it.fn dialog(ppp: f32, command: &str, filter: &str) -> (Harness<'static, PhotocraftApp>, u64) {- let mut h = Harness::builder().with_size(egui::vec2(1100.0, 760.0)).with_pixels_per_point(ppp).with_max_steps(64).build_eframe(|cc| {+ dialog_with_renderer(ppp, command, filter, false)+ }++ fn dialog_with_renderer(ppp: f32, command: &str, filter: &str, gpu: bool) -> (Harness<'static, PhotocraftApp>, u64) {+ let builder = Harness::builder().with_size(egui::vec2(1100.0, 760.0)).with_pixels_per_point(ppp).with_max_steps(64);+ let builder = if gpu { builder.wgpu() } else { builder };+ let mut h = builder.build_eframe(|cc| {PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default())});@@@ -144,41 -140,21 +150,56 @@@ fn capture(h: &mut Harness<'_, Photocrah.run_steps(2);}+ fn captured_ctrl_k(ppp: f32, gpu: bool) -> Harness<'static, PhotocraftApp> {+ let (mut h, id) = dialog_with_renderer(ppp, "edit.search", "search…", gpu);+ // Search's default is ⌘F (Photoshop); ⌘K is Preferences, so this also reports a conflict.+ let current = crate::shortcuts::pretty("Cmd+F");+ // On Windows and Linux the Ctrl key is the command modifier.+ capture(&mut h, ¤t, Key::ControlLeft, Modifiers::COMMAND, Key::K);+ assert_eq!(field(&h, id, "overrides")["edit.search"], json!("Cmd+K"), "@{ppp}x");+ assert_eq!(field(&h, id, "capture"), json!(false));+ let message = field(&h, id, "message");+ assert!(!message.as_str().unwrap().contains("ontrol"), "@{ppp}x: {message}");+ // The row shows the new shortcut.+ h.get_by_label(&crate::shortcuts::pretty("Cmd+K"));+ h+ }++#[test]+fn capture_key_press_records_shift_when_key_events_carry_no_modifier_bits() {+ // Same event pattern as Linux/Windows egui: modifier and letter Key events with empty bits.+ // Legacy capture → (F6, NONE) → shortcut_text → "F6"; capture_key_press → "Shift+F6".+ let key_event = |key: Key| Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE };+ let (mods, pressed) =+ crate::prefs_ui::capture_key_press(Modifiers::NONE, &input_state(vec![key_event(Key::ShiftLeft), key_event(Key::F6)], Modifiers::NONE));+ assert!(mods.shift);+ let (key, m) = pressed.expect("F6 press");+ assert_eq!(key, Key::F6);+ assert!(m.shift);+ assert_eq!(crate::prefs_ui::shortcut_text(key, m).as_deref(), Some("Shift+F6"));+ let (mods, pressed) = crate::prefs_ui::capture_key_press(Modifiers::NONE, &input_state(vec![key_event(Key::ShiftLeft)], Modifiers::NONE));+ assert!(mods.shift);+ assert!(pressed.is_none(), "modifier alone does not finish capture");+ let (_, pressed) = crate::prefs_ui::capture_key_press(mods, &input_state(vec![key_event(Key::F6)], Modifiers::NONE));+ let (_, m) = pressed.expect("letter in a later frame");+ assert!(m.shift, "captureMods carries Shift across frames");+ assert_eq!(crate::prefs_ui::shortcut_text(Key::F6, m).as_deref(), Some("Shift+F6"));+}++#[test]+fn shift_is_recorded_when_modifier_key_events_carry_no_bits() {+ // End-to-end: dialog capture → overrides JSON (shortcut_text → prefs::normalize_shortcut).+ let (mut h, id) = dialog(1.0, "edit.search", "search…");+ h.get_by_label(&crate::shortcuts::pretty("Cmd+F")).click();+ h.run_steps(2);+ key(&mut h, Key::ShiftLeft, true, Modifiers::NONE);+ h.run_steps(1);+ key(&mut h, Key::F6, true, Modifiers::NONE);+ h.run_steps(2);+ assert_eq!(field(&h, id, "overrides")["edit.search"], json!("Shift+F6"));+ assert_eq!(field(&h, id, "capture"), json!(false));+}+#[test]fn ctrl_k_is_recorded_as_ctrl_k_not_the_control_key() {for ppp in [1.0, 2.0] {diff --cc docs/development.mdindex 71380fcad,837f6c053..925e1502d--- a/docs/development.md+++ b/docs/development.md@@@ -59,8 -59,39 +59,39 @@@ cargo nextest run --workspaccargo test --doc --workspace # nextest does not run doctests```-[cargo-nextest](https://nexte.st) runs each test in its own process. `.config/nextest.toml` puts the GPU tests (`photocraft-gpu`, and ui-egui's integration and canvas/GPU tests) in a group of at most 4 at a time, because each process opens its own wgpu device and the in-process `gpu_lock()` no longer serializes them. On a 32-thread Windows machine the full workspace went from 297 s (`cargo test`) to about 120 s (#2204). Ignored tests run with `cargo nextest run --run-ignored only`. CI still runs `cargo test`, and a full `cargo test` stays the final check before a PR.+[cargo-nextest](https://nexte.st) runs each test in its own process. `.config/nextest.toml` puts the GPU tests (`photocraft-gpu`, and ui-egui's integration and canvas/GPU tests) in a group of at most 4 at a time, because each process opens its own wgpu device and the in-process `gpu_lock()` no longer serializes them. On a 32-thread Windows machine the full workspace went from 297 s (`cargo test`) to about 120 s (#2204). Ignored tests run with `cargo nextest run --run-ignored only`. CI runs it with `--profile ci` (fail-fast, a 10-minute hang timeout), plus `cargo test --doc` for the doctests (#6117); a full `cargo test` stays the final check before a PR.+ ### Shortcut capture without a GPU, and native snapshots++ The ordinary `shortcut_capture_tests` check modifier capture, conflicts, restored bindings and+ visible labels without starting a GPU renderer. `captured_shortcut_gpu_snapshots` repeats the Ctrl+K+ capture assertions at 1x and 2x with a native renderer when `PHOTOCRAFT_SHORTCUT_SNAPSHOTS` names+ an output directory. Its `gpu` test name selects the existing Nextest GPU group. It also holds+ `photocraft_testkit::gpu_lock`, requires successful rendering and+ checks physical image dimensions before saving both PNGs. As with the Camera Raw localization+ snapshots, pixel appearance is reviewed from the saved images rather than a golden-image test.++ On a native host with a working wgpu adapter, capture the two images into a fresh directory:++ ```sh+ (+ set -eu+ shortcut_snapshots="$(mktemp -d)"+ PHOTOCRAFT_SHORTCUT_SNAPSHOTS="$shortcut_snapshots" cargo test -p photocraft-ui-egui --lib \+ prefs_ui::shortcut_capture_tests::captured_shortcut_gpu_snapshots -- --exact+ test -s "$shortcut_snapshots/ctrl-k-1x.png"+ test -s "$shortcut_snapshots/ctrl-k-2x.png"+ printf 'Review the shortcut row and conflict message in %s\n' "$shortcut_snapshots"+ )+ ```++ The file checks intentionally reject a successful zero-test selection. Keep the fresh directory+ until both scales have been inspected: the row must show the captured shortcut without a stray ControlLeft+ key name, and the conflict message must remain readable. Rendering and file-write failures fail+ the opted-in test; an unset variable leaves the ordinary behavior tests available without a GPU.+ After review, remove only the two generated PNGs and their owned temporary directory. The same+ Rust test and variable work on Windows with the native shell's environment-variable syntax.+## Fonts (craft-fonts)Font assets shared by the Crafting Apps live in [storytold/craft-fonts](https://github.com/storytold/craft-fonts), never in this repo: don't commit font files here (Inter and JetBrains Mono in `assets/fonts/` are the only exceptions; new fonts go to craft-fonts). The rules are in `craftrules/standards/fonts.md` in a sibling `craftrules` checkout (see below); that repository is not public, so outside contributors can ask a maintainer for the rules that apply to their change.