mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Keep Q from toggling Quick Mask during Free Transform (#17799)
This commit is contained in:
1 parent
c5ca44cd2f
commit
3b24ea78dd
2 files changed
+50
No files matched your search
@@ -0,0 +1,35 @@
|
||||
use egui::{Key, Modifiers};
|
||||
use egui_kittest::Harness;
|
||||
use serde_json::json;
|
||||
|
||||
use super::tests::{app_harness, tap};
|
||||
use crate::{PhotocraftApp, Services};
|
||||
|
||||
type AppHarness = Harness<'static, Box<PhotocraftApp>>;
|
||||
|
||||
fn quick_mask(h: &AppHarness) -> bool {
|
||||
h.state().session.active().unwrap().doc.quick_mask.is_some()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quick_mask_shortcut_waits_for_free_transform_to_finish() {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Services::default());
|
||||
app.run("file.new", json!({"width": 120, "height": 100})).unwrap();
|
||||
app.run("select.rect", json!({"x": 20, "y": 20, "width": 60, "height": 50})).unwrap();
|
||||
let mut h = app_harness(app);
|
||||
|
||||
for (starts_in_quick_mask, finish) in [(false, Key::Enter), (true, Key::Escape)] {
|
||||
assert_eq!(quick_mask(&h), starts_in_quick_mask);
|
||||
tap(&mut h, Key::T, Modifiers::COMMAND);
|
||||
let transform = h.state().ui.transform.as_ref().expect("Free Transform opens from its shortcut").id;
|
||||
|
||||
tap(&mut h, Key::Q, Modifiers::NONE);
|
||||
assert_eq!(quick_mask(&h), starts_in_quick_mask, "Q keeps Quick Mask unchanged while Free Transform is live");
|
||||
assert_eq!(h.state().ui.transform.as_ref().map(|t| t.id), Some(transform), "the same Free Transform stays live");
|
||||
|
||||
tap(&mut h, finish, Modifiers::NONE);
|
||||
assert!(h.state().ui.transform.is_none(), "Enter and Escape close Free Transform");
|
||||
tap(&mut h, Key::Q, Modifiers::NONE);
|
||||
assert_eq!(quick_mask(&h), !starts_in_quick_mask, "Q toggles again when the transform is closed");
|
||||
}
|
||||
}
|
||||
@@ -698,6 +698,17 @@ fn pick_tool(app: &mut PhotocraftApp, letter: char, step: PickStep, plain: bool,
|
||||
/// through [`dispatch_as`].
|
||||
fn run_pressed(app: &mut PhotocraftApp, ctx: &egui::Context, f: &Fired) {
|
||||
let id = f.command.id.as_str();
|
||||
if f.source == FireSource::Key
|
||||
&& id == crate::panels::QUICK_MASK
|
||||
&& app.ui.transform.as_ref().is_some_and(|transform| {
|
||||
!transform.selection
|
||||
&& transform.content_aware.is_none()
|
||||
&& transform.session.warp().is_none()
|
||||
&& transform.session.current_mode() == craft::behavior::geometry::TransformMode::Free
|
||||
})
|
||||
{
|
||||
return;
|
||||
}
|
||||
// The Magnetic Lasso's bracket keys step its detection width, not the brush (#11688), until an outline is open.
|
||||
if app.ui.tool == Tool::MagneticLasso && !app.canvas_tools.selection.outline_open() {
|
||||
let step = match id {
|
||||
@@ -819,3 +830,7 @@ fn record(ctx: &egui::Context, id: &str, outcome: Outcome) {
|
||||
/// The whole-app key harness the key tests of this module share (`app_harness`, `tap`).
|
||||
#[cfg(test)]
|
||||
pub(crate) mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "quick_mask_free_transform_tests.rs"]
|
||||
mod quick_mask_free_transform_tests;
|
||||
Reference in new issue
Block a user