diff --git a/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs b/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs index fd2fe385cd..d404f99d52 100644 --- a/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs +++ b/crates/ui-egui/src/canvas/no_cursor_while_painting_tests.rs @@ -88,6 +88,36 @@ fn hides_during_a_real_stroke_and_restores_the_tip_on_release() { primary(&mut h, 100.0, false, Modifiers::ALT); } +#[test] +fn caps_lock_keeps_the_precise_crosshair_and_the_block_square_during_strokes() { + let crosshair = Cursor::Painted(PaintedCursor::Crosshair); + let hidden = Cursor::Painted(PaintedCursor::Hidden); + for tool in [Tool::Brush, Tool::Eraser] { + let mut h = harness(tool); + h.state_mut().background_jobs = false; + h.state_mut().run("layer.new.layer", json!({})).unwrap(); + h.state_mut().run("edit.fill", json!({"contents": "color", "color": "#ff8000"})).unwrap(); + h.state_mut().ui.tool_options.eraser_mode = "block".into(); + h.state_mut().session.tools.brush.size = 40.0; + paint_prefs(&mut h, true, false); + WindowHost::of(&h.ctx).set_caps_lock(Some(true)); + hover(&mut h, 100.0, 150.0, Modifiers::NONE); + let expected = canvas_cursor(&h); + if tool == Tool::Brush { + assert_eq!(expected, crosshair); + } else { + assert!(matches!(expected, Cursor::Painted(_))); + assert_ne!(expected, crosshair); + assert_ne!(expected, hidden); + } + + primary(&mut h, 100.0, true, Modifiers::NONE); + assert!(stroking(h.state()).is_some()); + assert_eq!(canvas_cursor(&h), expected); + primary(&mut h, 100.0, false, Modifiers::NONE); + } +} + fn check(h: &AppHarness, label: &str) -> (bool, Option) { let node = h.get_by_role_and_label(Role::CheckBox, label); let node = node.accesskit_node(); diff --git a/crates/ui-egui/src/tools/brush_cursor.rs b/crates/ui-egui/src/tools/brush_cursor.rs index 948740d515..19118eb9c8 100644 --- a/crates/ui-egui/src/tools/brush_cursor.rs +++ b/crates/ui-egui/src/tools/brush_cursor.rs @@ -142,7 +142,7 @@ pub(crate) fn cursor(app: &PhotocraftApp, cx: &ToolContext<'_>, painting: bool) if crate::canvas::cursor_policy::source_target(tool, option, prefs.painting, cx.caps_lock) { return crate::canvas::cursor_policy::sample_target(); } - if painting && prefs.no_cursor_while_painting && !prefs.show_only_crosshair_while_painting { + if painting && prefs.no_cursor_while_painting && !prefs.show_only_crosshair_while_painting && !cx.caps_lock { return Cursor::Painted(PaintedCursor::Hidden); } let centre = crate::canvas::cursor_policy::brush_tip_centre(tool, option, prefs.show_crosshair_in_brush_tip);