Preserve Caps Lock cursors during brush strokes

This commit is contained in:
yoriswind committed 2026-12-01 18:34:20 -08:00
1 parent 2d865a1e16
commit dd20a10779
2 files changed
+31 -1

No files matched your search

@@ -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<Toggled>) {
let node = h.get_by_role_and_label(Role::CheckBox, label);
let node = node.accesskit_node();
+1 -1
View File
@@ -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);