From 34c650aaa1356393875ba59442acbedc65d0e310 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Sun, 15 Nov 2026 02:55:19 -0800 Subject: [PATCH 1/6] Support digit shortcuts for Magic Eraser opacity --- .../src/background_eraser_digit_keys_tests.rs | 2 +- crates/ui-egui/src/input.rs | 3 + .../input/magic_eraser_digit_keys_tests.rs | 55 +++++++++++++++++++ crates/ui-egui/src/input/opacity_keys.rs | 15 +++-- 4 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 crates/ui-egui/src/input/magic_eraser_digit_keys_tests.rs diff --git a/crates/ui-egui/src/background_eraser_digit_keys_tests.rs b/crates/ui-egui/src/background_eraser_digit_keys_tests.rs index 9cddb5a7eb3..a9e0d40bdf8 100644 --- a/crates/ui-egui/src/background_eraser_digit_keys_tests.rs +++ b/crates/ui-egui/src/background_eraser_digit_keys_tests.rs @@ -98,7 +98,7 @@ fn other_tools_digits_are_unchanged() { assert!((layer(&a).0 - 0.3).abs() < 1e-6); assert_eq!(tolerance(&a), 50.0); // The tools whose number is a strength, exposure or tolerance of their own still ignore the digits. - for tool in [Tool::ColorReplacement, Tool::Dodge, Tool::Smudge, Tool::MagicEraser] { + for tool in [Tool::ColorReplacement, Tool::Dodge, Tool::Smudge] { let mut a = app(tool); let before = (a.session.tools.brush.clone(), layer(&a), a.ui.tool_options.clone()); press(&mut a, 3, false, 0.0); diff --git a/crates/ui-egui/src/input.rs b/crates/ui-egui/src/input.rs index b147c2182d7..b021371d81f 100644 --- a/crates/ui-egui/src/input.rs +++ b/crates/ui-egui/src/input.rs @@ -14,3 +14,6 @@ pub mod spring_tools; pub mod stylus; pub(super) mod tool_shortcuts; pub mod touch_twins; + +#[cfg(test)] +mod magic_eraser_digit_keys_tests; diff --git a/crates/ui-egui/src/input/magic_eraser_digit_keys_tests.rs b/crates/ui-egui/src/input/magic_eraser_digit_keys_tests.rs new file mode 100644 index 00000000000..431428e436a --- /dev/null +++ b/crates/ui-egui/src/input/magic_eraser_digit_keys_tests.rs @@ -0,0 +1,55 @@ +//! #11999: Magic Eraser digits set its Opacity; Shift digits set the same field. + +use serde_json::json; + +use crate::PhotocraftApp; +use crate::opacity_keys::press; +use crate::state::Tool; + +fn app(tool: Tool) -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 32, "height": 32})).unwrap(); + app.run("layer.new.layer", json!({})).unwrap(); + app.ui.tool = tool; + app +} + +fn layer(app: &PhotocraftApp) -> (f32, f32) { + let st = app.session.active().unwrap(); + let l = st.doc.layer(st.active_layer.unwrap()).unwrap(); + (l.opacity, l.fill_opacity) +} + +#[test] +fn digits_and_shift_digits_set_magic_eraser_opacity() { + let mut a = app(Tool::MagicEraser); + assert_eq!(a.ui.tool_options.magic_eraser_opacity, 100.0); + press(&mut a, 5, false, 0.0); + assert_eq!(a.ui.tool_options.magic_eraser_opacity, 50.0); + press(&mut a, 0, false, 5000.0); + assert_eq!(a.ui.tool_options.magic_eraser_opacity, 100.0); + press(&mut a, 3, false, 10000.0); + assert_eq!(a.ui.tool_options.magic_eraser_opacity, 30.0); + press(&mut a, 4, false, 20000.0); + press(&mut a, 5, false, 20300.0); + assert_eq!(a.ui.tool_options.magic_eraser_opacity, 45.0); + let options = serde_json::to_value(&a.ui.tool_options).unwrap(); + assert_eq!(options["magic_eraser_opacity"], json!(45.0)); + press(&mut a, 5, true, 30000.0); + assert_eq!(a.ui.tool_options.magic_eraser_opacity, 50.0); +} + +#[test] +fn magic_eraser_digits_leave_tolerance_layer_and_brush_alone() { + let mut a = app(Tool::MagicEraser); + let tolerance = a.ui.tool_options.tolerance; + let layer_before = layer(&a); + let brush = a.session.tools.brush.clone(); + press(&mut a, 5, false, 0.0); + assert_eq!(a.ui.tool_options.tolerance, tolerance); + assert_eq!(layer(&a), layer_before); + assert_eq!(a.session.tools.brush, brush); + press(&mut a, 0, false, 5000.0); + press(&mut a, 0, false, 5100.0); + assert_eq!(a.ui.tool_options.magic_eraser_opacity, 100.0, "unmeasured 00 keeps the first zero's value"); +} diff --git a/crates/ui-egui/src/input/opacity_keys.rs b/crates/ui-egui/src/input/opacity_keys.rs index 41c571f3122..de88690dc91 100644 --- a/crates/ui-egui/src/input/opacity_keys.rs +++ b/crates/ui-egui/src/input/opacity_keys.rs @@ -3,9 +3,9 @@ //! Eraser they set the brush's Opacity (⇧: Flow, swapped while airbrush build-up is on; the Pencil has no Flow, so its ⇧ //! digits set Opacity too, #11967); with the Gradient or Paint Bucket their //! Opacity; with tools that have no opacity of their own (Move, the selection tools, Type…) the -//! active layer's Opacity (⇧: Fill); with the Background Eraser its Tolerance (#11907). Tools whose -//! number is a strength or exposure are left alone. -//! ⌥+digit sets the Smoothing of the tools that show it (Brush, Pencil, Eraser; #11892). +//! active layer's Opacity (⇧: Fill); with the Background Eraser its Tolerance (#11907); and with +//! Magic Eraser its Opacity (#11999). Tools whose number is a strength or exposure are left alone. +//! ⌥+digit sets Smoothing for tools that show it (Brush, Pencil, Eraser; #11892). use egui::{Event, Key}; use serde_json::json; @@ -30,6 +30,8 @@ enum Target { ToolOpacity, /// The Background Eraser's Tolerance option. BgTolerance, + /// The Magic Eraser's Opacity option. + MagicEraserOpacity, /// The active layer's opacity (⇧: fill). Layer, None, @@ -41,8 +43,9 @@ fn target(tool: Tool) -> Target { Tool::Pencil => Target::Brush { flow: false }, Tool::Gradient | Tool::PaintBucket => Target::ToolOpacity, Tool::BackgroundEraser => Target::BgTolerance, - // Their options-bar number is a strength, exposure or tolerance, not this opacity. - t if t.is_brushlike() || t == Tool::MagicEraser => Target::None, + Tool::MagicEraser => Target::MagicEraserOpacity, + // Other brush-like tools whose number is a strength, exposure or tolerance keep no target. + t if t.is_brushlike() => Target::None, _ => Target::Layer, } } @@ -165,6 +168,8 @@ fn apply(app: &mut PhotocraftApp, percent: f32, shift: bool) { (Target::ToolOpacity, false) => app.ui.tool_options.fill_opacity = percent, // The Tolerance field starts at 1%; `00` (0%) keeps today's value rather than guessing. (Target::BgTolerance, false) if percent >= 1.0 => app.ui.tool_options.bg_tolerance = percent, + // The field starts at 1%; an unmeasured 00 keeps its current value. + (Target::MagicEraserOpacity, _) if percent >= 1.0 => app.ui.tool_options.magic_eraser_opacity = percent, (Target::Layer, _) => { // The locked Background has no opacity or fill. let Some(st) = app.session.active() else { return }; From 2f19768c42673ab562d412e44e53ebaa3c89e8fb Mon Sep 17 00:00:00 2001 From: yoriswind Date: Sun, 15 Nov 2026 03:55:58 -0800 Subject: [PATCH 2/6] Keep consecutive digit entry within its originating tool --- .../input/magic_eraser_digit_keys_tests.rs | 16 ++++++++++ crates/ui-egui/src/input/opacity_keys.rs | 32 ++++++++++++++++--- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/input/magic_eraser_digit_keys_tests.rs b/crates/ui-egui/src/input/magic_eraser_digit_keys_tests.rs index 431428e436a..9609c657a33 100644 --- a/crates/ui-egui/src/input/magic_eraser_digit_keys_tests.rs +++ b/crates/ui-egui/src/input/magic_eraser_digit_keys_tests.rs @@ -53,3 +53,19 @@ fn magic_eraser_digits_leave_tolerance_layer_and_brush_alone() { press(&mut a, 0, false, 5100.0); assert_eq!(a.ui.tool_options.magic_eraser_opacity, 100.0, "unmeasured 00 keeps the first zero's value"); } +#[test] +fn digits_do_not_pair_across_tools() { + let mut brush_to_magic = app(Tool::Brush); + press(&mut brush_to_magic, 4, false, 0.0); + brush_to_magic.ui.tool = Tool::MagicEraser; + press(&mut brush_to_magic, 5, false, 300.0); + assert_eq!(brush_to_magic.session.tools.brush.opacity, 0.4); + assert_eq!(brush_to_magic.ui.tool_options.magic_eraser_opacity, 50.0); + + let mut magic_to_brush = app(Tool::MagicEraser); + press(&mut magic_to_brush, 4, false, 0.0); + magic_to_brush.ui.tool = Tool::Brush; + press(&mut magic_to_brush, 5, false, 300.0); + assert_eq!(magic_to_brush.ui.tool_options.magic_eraser_opacity, 40.0); + assert_eq!(magic_to_brush.session.tools.brush.opacity, 0.5); +} diff --git a/crates/ui-egui/src/input/opacity_keys.rs b/crates/ui-egui/src/input/opacity_keys.rs index de88690dc91..471ec00acd7 100644 --- a/crates/ui-egui/src/input/opacity_keys.rs +++ b/crates/ui-egui/src/input/opacity_keys.rs @@ -16,8 +16,8 @@ use crate::state::Tool; /// A second digit within this long of the first makes a two-digit value. const TWO_DIGITS_MS: f64 = 800.0; -/// The first digit of a possible two-digit value: (digit, ⇧ held, when). -pub type Pending = Option<(u8, bool, f64)>; +/// The first digit of a possible two-digit value: (digit, ⇧ held, when, originating tool). +pub type Pending = Option<(u8, bool, f64, Tool)>; /// What a tool's number keys change. #[derive(Clone, Copy, Debug, PartialEq)] @@ -132,10 +132,11 @@ pub fn handle(app: &mut PhotocraftApp, ctx: &egui::Context) { /// One digit press at `now` (ms). pub fn press(app: &mut PhotocraftApp, d: u8, shift: bool, now: f64) { + let tool = app.ui.tool; let percent = match app.opacity_keys.take() { - Some((first, s, at)) if s == shift && now - at < TWO_DIGITS_MS && now >= at => f32::from(first * 10 + d), + Some((first, s, at, started_with)) if started_with == tool && s == shift && now - at < TWO_DIGITS_MS && now >= at => f32::from(first * 10 + d), _ => { - app.opacity_keys = Some((d, shift, now)); + app.opacity_keys = Some((d, shift, now, tool)); if d == 0 { 100.0 } else { f32::from(d) * 10.0 } } }; @@ -202,6 +203,29 @@ mod tests { (l.opacity, l.fill_opacity) } + #[test] + fn two_digits_do_not_pair_across_tools() { + // Brush and Eraser both target shared brush opacity, but a tool switch starts a new value. + let mut brush_then_eraser = app(Tool::Brush); + press(&mut brush_then_eraser, 4, false, 0.0); + brush_then_eraser.ui.tool = Tool::Eraser; + press(&mut brush_then_eraser, 5, false, 300.0); + assert_eq!(brush_then_eraser.session.tools.brush.opacity, 0.5); + + // Gradient and Paint Bucket share their opacity option but still have separate sequences. + let mut gradient_then_bucket = app(Tool::Gradient); + press(&mut gradient_then_bucket, 4, false, 0.0); + gradient_then_bucket.ui.tool = Tool::PaintBucket; + press(&mut gradient_then_bucket, 5, false, 300.0); + assert_eq!(gradient_then_bucket.ui.tool_options.fill_opacity, 50.0); + + // Same-tool pairs remain exact. + let mut same_tool = app(Tool::Brush); + press(&mut same_tool, 4, false, 0.0); + press(&mut same_tool, 5, false, 300.0); + assert_eq!(same_tool.session.tools.brush.opacity, 0.45); + } + #[test] fn digits_set_the_brush_opacity_and_shift_digits_its_flow() { let mut a = app(Tool::Brush); From d856020472592809d2edf9e099daea5d9b7e825b Mon Sep 17 00:00:00 2001 From: Yoris Date: Sun, 15 Nov 2026 10:59:02 -0800 Subject: [PATCH 3/6] Keep CI-produced photocraft-text lock dependencies canonical --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index d3935c94a4e..03aadc6d205 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5859,8 +5859,8 @@ dependencies = [ name = "photocraft-text" version = "0.23.1" dependencies = [ - "craft-plist", "base64 0.23.1", + "craft-plist", "craft-psd", "flate2", "parley", From 8663d7f1146af7e5a8650ad729d45c400d46c7a1 Mon Sep 17 00:00:00 2001 From: Yoris Date: Sun, 15 Nov 2026 13:37:14 -0800 Subject: [PATCH 4/6] Match upstream shortcut fixture initializer without changing assertions --- .../ui-egui/src/prefs/prefs_ui/shortcut_set_switch_tests.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/prefs/prefs_ui/shortcut_set_switch_tests.rs b/crates/ui-egui/src/prefs/prefs_ui/shortcut_set_switch_tests.rs index 31bc9bf7110..68a82501d92 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/shortcut_set_switch_tests.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/shortcut_set_switch_tests.rs @@ -165,9 +165,8 @@ fn an_unmodified_set_switches_at_once() { fn an_action_function_key_is_no_edit() { let (mut h, first) = dialog(); h.state_mut().ui.dialogs.retain(|d| d.id != first); - let sepia = h.state().session.actions.list.len(); - h.state_mut().session.actions.list.push(photocraft_engine::actions_cmds::Action::new("Sepia", vec![])); - crate::actions::assign_shortcut(h.state_mut(), sepia, "F2").unwrap(); + h.state_mut().session.actions.list.push(photocraft_engine::actions_cmds::Action::new("Sepia", Vec::new())); + crate::actions::assign_shortcut(h.state_mut(), 0, "F2").unwrap(); let ctx = h.ctx.clone(); let id = crate::menus::invoke(h.state_mut(), &ctx, "edit.keyboardShortcuts", json!({})).unwrap()["dialog"].as_u64().unwrap(); h.run_steps(4); From fce0beda0afb8d9849bfeb744d038e57a2ee94a2 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Sun, 15 Nov 2026 16:05:14 -0800 Subject: [PATCH 5/6] Preserve shared digit pairing outside issue #11999 --- .../input/magic_eraser_digit_keys_tests.rs | 38 ++++++++++++------- crates/ui-egui/src/input/opacity_keys.rs | 32 ++-------------- 2 files changed, 29 insertions(+), 41 deletions(-) diff --git a/crates/ui-egui/src/input/magic_eraser_digit_keys_tests.rs b/crates/ui-egui/src/input/magic_eraser_digit_keys_tests.rs index 9609c657a33..4411d1a73e2 100644 --- a/crates/ui-egui/src/input/magic_eraser_digit_keys_tests.rs +++ b/crates/ui-egui/src/input/magic_eraser_digit_keys_tests.rs @@ -54,18 +54,30 @@ fn magic_eraser_digits_leave_tolerance_layer_and_brush_alone() { assert_eq!(a.ui.tool_options.magic_eraser_opacity, 100.0, "unmeasured 00 keeps the first zero's value"); } #[test] -fn digits_do_not_pair_across_tools() { - let mut brush_to_magic = app(Tool::Brush); - press(&mut brush_to_magic, 4, false, 0.0); - brush_to_magic.ui.tool = Tool::MagicEraser; - press(&mut brush_to_magic, 5, false, 300.0); - assert_eq!(brush_to_magic.session.tools.brush.opacity, 0.4); - assert_eq!(brush_to_magic.ui.tool_options.magic_eraser_opacity, 50.0); +fn digit_pairs_preserve_the_existing_shared_cross_tool_sequence() { + // The new target inherits the same pending-digit sequence as Main's existing tools. + let mut brush_to_selected = app(Tool::Brush); + press(&mut brush_to_selected, 4, false, 0.0); + brush_to_selected.ui.tool = Tool::MagicEraser; + press(&mut brush_to_selected, 5, false, 300.0); + assert_eq!(brush_to_selected.session.tools.brush.opacity, 0.4); + assert_eq!(brush_to_selected.ui.tool_options.magic_eraser_opacity, 45.0); - let mut magic_to_brush = app(Tool::MagicEraser); - press(&mut magic_to_brush, 4, false, 0.0); - magic_to_brush.ui.tool = Tool::Brush; - press(&mut magic_to_brush, 5, false, 300.0); - assert_eq!(magic_to_brush.ui.tool_options.magic_eraser_opacity, 40.0); - assert_eq!(magic_to_brush.session.tools.brush.opacity, 0.5); + // A selected-tool digit still contributes to the unchanged legacy Brush sequence. + let mut selected_to_brush = app(Tool::MagicEraser); + press(&mut selected_to_brush, 4, false, 0.0); + selected_to_brush.ui.tool = Tool::Brush; + press(&mut selected_to_brush, 5, false, 300.0); + assert_eq!(selected_to_brush.ui.tool_options.magic_eraser_opacity, 40.0); + assert_eq!(selected_to_brush.session.tools.brush.opacity, 0.45); + + // Consuming the first pair must also leave the next legacy digit unpaired. + let mut through_selected = app(Tool::Brush); + press(&mut through_selected, 4, false, 0.0); + through_selected.ui.tool = Tool::MagicEraser; + press(&mut through_selected, 5, false, 300.0); + through_selected.ui.tool = Tool::Brush; + press(&mut through_selected, 6, false, 400.0); + assert_eq!(through_selected.ui.tool_options.magic_eraser_opacity, 45.0); + assert_eq!(through_selected.session.tools.brush.opacity, 0.6); } diff --git a/crates/ui-egui/src/input/opacity_keys.rs b/crates/ui-egui/src/input/opacity_keys.rs index 471ec00acd7..de88690dc91 100644 --- a/crates/ui-egui/src/input/opacity_keys.rs +++ b/crates/ui-egui/src/input/opacity_keys.rs @@ -16,8 +16,8 @@ use crate::state::Tool; /// A second digit within this long of the first makes a two-digit value. const TWO_DIGITS_MS: f64 = 800.0; -/// The first digit of a possible two-digit value: (digit, ⇧ held, when, originating tool). -pub type Pending = Option<(u8, bool, f64, Tool)>; +/// The first digit of a possible two-digit value: (digit, ⇧ held, when). +pub type Pending = Option<(u8, bool, f64)>; /// What a tool's number keys change. #[derive(Clone, Copy, Debug, PartialEq)] @@ -132,11 +132,10 @@ pub fn handle(app: &mut PhotocraftApp, ctx: &egui::Context) { /// One digit press at `now` (ms). pub fn press(app: &mut PhotocraftApp, d: u8, shift: bool, now: f64) { - let tool = app.ui.tool; let percent = match app.opacity_keys.take() { - Some((first, s, at, started_with)) if started_with == tool && s == shift && now - at < TWO_DIGITS_MS && now >= at => f32::from(first * 10 + d), + Some((first, s, at)) if s == shift && now - at < TWO_DIGITS_MS && now >= at => f32::from(first * 10 + d), _ => { - app.opacity_keys = Some((d, shift, now, tool)); + app.opacity_keys = Some((d, shift, now)); if d == 0 { 100.0 } else { f32::from(d) * 10.0 } } }; @@ -203,29 +202,6 @@ mod tests { (l.opacity, l.fill_opacity) } - #[test] - fn two_digits_do_not_pair_across_tools() { - // Brush and Eraser both target shared brush opacity, but a tool switch starts a new value. - let mut brush_then_eraser = app(Tool::Brush); - press(&mut brush_then_eraser, 4, false, 0.0); - brush_then_eraser.ui.tool = Tool::Eraser; - press(&mut brush_then_eraser, 5, false, 300.0); - assert_eq!(brush_then_eraser.session.tools.brush.opacity, 0.5); - - // Gradient and Paint Bucket share their opacity option but still have separate sequences. - let mut gradient_then_bucket = app(Tool::Gradient); - press(&mut gradient_then_bucket, 4, false, 0.0); - gradient_then_bucket.ui.tool = Tool::PaintBucket; - press(&mut gradient_then_bucket, 5, false, 300.0); - assert_eq!(gradient_then_bucket.ui.tool_options.fill_opacity, 50.0); - - // Same-tool pairs remain exact. - let mut same_tool = app(Tool::Brush); - press(&mut same_tool, 4, false, 0.0); - press(&mut same_tool, 5, false, 300.0); - assert_eq!(same_tool.session.tools.brush.opacity, 0.45); - } - #[test] fn digits_set_the_brush_opacity_and_shift_digits_its_flow() { let mut a = app(Tool::Brush); From 0a611fc735430da98d9e24e06bd932299d60a3f6 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Wed, 18 Nov 2026 10:31:39 -0800 Subject: [PATCH 6/6] test: apply bounded CI formatting repair for PR15102 --- .../src/input/magic_eraser_digit_keys_tests.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/input/magic_eraser_digit_keys_tests.rs b/crates/ui-egui/src/input/magic_eraser_digit_keys_tests.rs index bdf1620a1c7..2f281aa5d38 100644 --- a/crates/ui-egui/src/input/magic_eraser_digit_keys_tests.rs +++ b/crates/ui-egui/src/input/magic_eraser_digit_keys_tests.rs @@ -19,7 +19,18 @@ fn press(app: &mut PhotocraftApp, digit: u8, shift: bool, now_ms: f64) { let commands = if shift { [D::SecondZero, D::SecondOne, D::SecondTwo, D::SecondThree, D::SecondFour, D::SecondFive, D::SecondSix, D::SecondSeven, D::SecondEight, D::SecondNine] } else { - [D::OpacityZero, D::OpacityOne, D::OpacityTwo, D::OpacityThree, D::OpacityFour, D::OpacityFive, D::OpacitySix, D::OpacitySeven, D::OpacityEight, D::OpacityNine] + [ + D::OpacityZero, + D::OpacityOne, + D::OpacityTwo, + D::OpacityThree, + D::OpacityFour, + D::OpacityFive, + D::OpacitySix, + D::OpacitySeven, + D::OpacityEight, + D::OpacityNine, + ] }; let mut fired = crate::blend_keys::test_fired(commands[usize::from(digit)].into()); fired.time = now_ms / 1000.0;