mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 09:26:43 +00:00
Crop: Shift+H, Shift+P and Shift+I switch tools again (#9232)
egui's consume_key ignores an extra Shift, so the Crop tool's plain H/P/I checks also took Shift+H/P/I before the tool-switch loop saw them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
486afd82cc
commit
239f5604a0
2 files changed
+39
-4
No files matched your search
@@ -122,18 +122,19 @@ pub fn hides_outside(app: &PhotocraftApp) -> bool {
|
||||
/// H with the Crop tool showing a box and no drag in progress toggles Show Cropped Area (in
|
||||
/// Classic Mode, where the option is greyed out, H is taken and does nothing), and P Use Classic
|
||||
/// Mode. Returns true when a key was used; otherwise H stays the Hand tool key and P the Pen's.
|
||||
/// ⇧H and ⇧P are always the tool keys (`consume_key` would also take them: it ignores ⇧).
|
||||
pub fn keys(app: &mut PhotocraftApp, ctx: &egui::Context) -> bool {
|
||||
if app.ui.tool != Tool::Crop || app.ui.crop_rect.is_none() || app.crop.drag.is_some() {
|
||||
return false;
|
||||
}
|
||||
if ctx.input_mut(|i| i.consume_key(Modifiers::NONE, Key::H)) {
|
||||
if ctx.input_mut(|i| !i.modifiers.shift && i.consume_key(Modifiers::NONE, Key::H)) {
|
||||
let s = &mut app.ui.tool_options.crop_shield;
|
||||
if !s.classic_mode {
|
||||
s.show_cropped_area = !s.show_cropped_area;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if ctx.input_mut(|i| i.consume_key(Modifiers::NONE, Key::P)) {
|
||||
if ctx.input_mut(|i| !i.modifiers.shift && i.consume_key(Modifiers::NONE, Key::P)) {
|
||||
let s = &mut app.ui.tool_options.crop_shield;
|
||||
s.classic_mode = !s.classic_mode;
|
||||
// The view follows at once, about its own centre: default mode turns it with the frame,
|
||||
@@ -342,6 +343,25 @@ mod tests {
|
||||
assert!(app.ui.tool_options.crop_shield.show_cropped_area);
|
||||
}
|
||||
|
||||
/// ⇧H and ⇧P are the Hand and Pen tool keys even with a crop box: egui's `consume_key` ignores
|
||||
/// an extra ⇧, so the plain-key checks must refuse it.
|
||||
#[test]
|
||||
fn shift_h_and_shift_p_switch_tools_instead_of_crop_options() {
|
||||
for (key, tool) in [(Key::H, Tool::Hand), (Key::P, Tool::Pen)] {
|
||||
let mut app = crop_app();
|
||||
assert!(app.session.prefs().tools.use_shift_key_for_tool_switch);
|
||||
let before = app.ui.tool_options.crop_shield.clone();
|
||||
let ctx = egui::Context::default();
|
||||
ctx.input_mut(|i| {
|
||||
i.modifiers = Modifiers::SHIFT;
|
||||
i.events.push(egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::SHIFT });
|
||||
});
|
||||
crate::shortcuts::handle(&mut app, &ctx);
|
||||
assert_eq!(app.ui.tool, tool, "{key:?}");
|
||||
assert_eq!(app.ui.tool_options.crop_shield, before, "{key:?} leaves Show Cropped Area and Classic Mode alone");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_color_picker_sets_the_custom_colour() {
|
||||
let mut app = crop_app();
|
||||
|
||||
@@ -260,12 +260,12 @@ pub fn chosen(app: &mut PhotocraftApp) {
|
||||
}
|
||||
|
||||
/// I with the Crop tool (no text field focused, which the caller checks): Front Image. Returns
|
||||
/// true when the key was used; otherwise I stays the Eyedropper tool key.
|
||||
/// true when the key was used; otherwise I (and always ⇧I) stays the Eyedropper tool key.
|
||||
pub fn keys(app: &mut PhotocraftApp, ctx: &egui::Context) -> bool {
|
||||
if app.ui.tool != Tool::Crop || app.crop.drag.is_some() || app.session.active().is_none() {
|
||||
return false;
|
||||
}
|
||||
if ctx.input_mut(|i| i.consume_key(Modifiers::NONE, egui::Key::I)) {
|
||||
if ctx.input_mut(|i| !i.modifiers.shift && i.consume_key(Modifiers::NONE, egui::Key::I)) {
|
||||
front_image(app);
|
||||
crate::crop_ui::apply_ratio(app);
|
||||
return true;
|
||||
@@ -497,6 +497,21 @@ mod tests {
|
||||
assert!(!keys(&mut app2, &ctx));
|
||||
}
|
||||
|
||||
/// ⇧I is the Eyedropper group's key even with the Crop tool, not Front Image.
|
||||
#[test]
|
||||
fn shift_i_with_the_crop_tool_switches_to_the_eyedropper() {
|
||||
let mut app = app(SampleType::U8);
|
||||
let ratio = app.ui.tool_options.crop_ratio.clone();
|
||||
let ctx = egui::Context::default();
|
||||
ctx.input_mut(|i| {
|
||||
i.modifiers = Modifiers::SHIFT;
|
||||
i.events.push(egui::Event::Key { key: egui::Key::I, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::SHIFT });
|
||||
});
|
||||
crate::shortcuts::handle(&mut app, &ctx);
|
||||
assert_eq!(app.ui.tool, Tool::Eyedropper);
|
||||
assert_eq!(app.ui.tool_options.crop_ratio, ratio);
|
||||
}
|
||||
|
||||
/// Committing a W x H x Resolution crop resamples the frame's area to exactly W x H px and sets
|
||||
/// the resolution, in one undo step, at 8 and 16 bits.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user