mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge pull request #18689
This commit is contained in:
commit
439e74fcea
2 files changed
+52
No files matched your search
@@ -138,6 +138,10 @@ fn find<'a>(rows: &'a mut [Row], id: &str) -> Option<&'a mut Row> {
|
||||
/// A live row shows the chord the runtime's keymap runs its command for (`commands::chord`: overrides included, a
|
||||
/// key another command wins left out); a catalogue row shows its text.
|
||||
fn shortcut_of(app: &PhotocraftApp, id: &str, catalogue: Option<&str>) -> Option<Chord> {
|
||||
// Quick Mask has a key binding without a hint in the Select menu.
|
||||
if id == crate::panels::QUICK_MASK {
|
||||
return None;
|
||||
}
|
||||
if is_live(id) {
|
||||
return craft::ui::runtime::commands::chord(app.ctx(), &crate::shortcut_dispatch::keymap_command(id));
|
||||
}
|
||||
@@ -473,3 +477,7 @@ fn build(app: &PhotocraftApp) -> Built {
|
||||
#[cfg(test)]
|
||||
#[path = "background_entry_swap_tests.rs"]
|
||||
mod background_entry_swap_tests;
|
||||
|
||||
#[cfg(all(test, not(target_arch = "wasm32")))]
|
||||
#[path = "quick_mask_shortcut_text_tests.rs"]
|
||||
mod quick_mask_shortcut_text_tests;
|
||||
@@ -0,0 +1,44 @@
|
||||
use egui::{Key, Modifiers};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::control::{ControlRequest, Reply};
|
||||
use crate::input::shortcut_dispatch::tests::{app_harness, tap};
|
||||
use crate::panels::QUICK_MASK;
|
||||
use crate::{PhotocraftApp, Services};
|
||||
|
||||
fn quick_mask_menu_row(app: &mut PhotocraftApp) -> Option<Value> {
|
||||
let ctx = app.ctx().clone();
|
||||
let (request, _reply) = ControlRequest::new("ui.menu.list", json!({}));
|
||||
let Reply::Done(reply) = crate::control::handle(app, &ctx, &request) else { return None };
|
||||
reply["result"].as_array()?.iter().find(|row| row["id"] == QUICK_MASK && row["path"] == json!(["Select"])).cloned()
|
||||
}
|
||||
|
||||
fn quick_mask(app: &PhotocraftApp) -> bool {
|
||||
app.session.active().is_some_and(|state| state.doc.quick_mask.is_some())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quick_mask_menu_omits_the_hint_while_q_still_toggles_after_a_shortcut_reset() {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Services::default());
|
||||
app.run("file.new", json!({"width": 64, "height": 48})).unwrap();
|
||||
let mut h = app_harness(app);
|
||||
let row = quick_mask_menu_row(h.state_mut()).expect("Quick Mask stays in the Select menu");
|
||||
assert!(row["shortcut"].is_null(), "the Select menu does not show a Quick Mask shortcut: {row}");
|
||||
|
||||
tap(&mut h, Key::Q, Modifiers::NONE);
|
||||
assert!(quick_mask(h.state()), "Q is bound by default");
|
||||
tap(&mut h, Key::Q, Modifiers::NONE);
|
||||
assert!(!quick_mask(h.state()));
|
||||
|
||||
h.state_mut().run("edit.keyboardShortcuts", json!({"set": {(QUICK_MASK): ""}})).unwrap();
|
||||
h.run_steps(2);
|
||||
tap(&mut h, Key::Q, Modifiers::NONE);
|
||||
assert!(!quick_mask(h.state()), "the user can remove Q");
|
||||
|
||||
h.state_mut().run("edit.keyboardShortcuts", json!({"reset": true})).unwrap();
|
||||
h.run_steps(2);
|
||||
tap(&mut h, Key::Q, Modifiers::NONE);
|
||||
assert!(quick_mask(h.state()), "reset restores Q");
|
||||
let row = quick_mask_menu_row(h.state_mut()).expect("Quick Mask stays in the Select menu");
|
||||
assert!(row["shortcut"].is_null(), "the Select menu does not show a Quick Mask shortcut: {row}");
|
||||
}
|
||||
Reference in new issue
Block a user