M8: invert zoom direction tests: Ctrl wheel, panning unchanged, pinch both ways, off persists (#2147 review)

Tests only. Ctrl+wheel joins Cmd+wheel; panning (plain wheel, Cmd/Ctrl+wheel and Shift+wheel with Scroll wheel zoom on) is compared between invert on and off; the pinch runs with Scroll wheel zoom on and off and with factors above and below 1; the pref's off value is saved and reloaded.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Model-Effort: Opus 5.5 triaged and briefed; Sonnet 5.5 verified and wrote at medium
This commit is contained in:
Trevor BrownandClaude Sonnet 5.5 committed 2026-11-09 15:11:14 -05:00
1 parent 6fce958ae6
commit 1ef0c16fdf
2 files changed
+36 -14

No files matched your search

+5
View File
@@ -115,6 +115,11 @@ fn the_invert_zoom_preference_toggles_and_is_saved() {
let loaded: crate::Prefs = serde_json::from_value(saved).unwrap();
assert!(loaded.invert_zoom);
assert_eq!(s.execute("pref.invertZoom", &json!({"on": false})).unwrap()["on"], false);
assert!(!s.prefs.invert_zoom);
let saved = serde_json::to_value(&s.prefs).unwrap();
assert_eq!(saved["invert_zoom"], false);
let loaded: crate::Prefs = serde_json::from_value(saved).unwrap();
assert!(!loaded.invert_zoom, "off persists after being on");
// Preferences saved before the setting existed read it as off.
let old: crate::Prefs = serde_json::from_value(json!({"theme": "dark"})).unwrap();
assert!(!old.invert_zoom);
+31 -14
View File
@@ -134,12 +134,14 @@ fn the_swap_keeps_egui_rates() {
#[test]
fn invert_zoom_reverses_cmd_or_ctrl_wheel_by_the_same_factor() {
let (mut off, mut on) = (Canvas::with_invert(false, false), Canvas::with_invert(false, true));
let (a, b, _) = off.gesture(wheel(MouseWheelUnit::Line, 3.0, Modifiers::COMMAND), Modifiers::COMMAND);
let (c, d, _) = on.gesture(wheel(MouseWheelUnit::Line, 3.0, Modifiers::COMMAND), Modifiers::COMMAND);
assert!(b.0 > a.0 * 1.05, "off zooms in: {a:?} -> {b:?}");
assert!(d.0 < c.0 / 1.05, "on zooms out: {c:?} -> {d:?}");
assert!(((b.0 / a.0) * (d.0 / c.0) - 1.0).abs() < 1e-3, "by the same factor");
for mods in [Modifiers::COMMAND, Modifiers::CTRL] {
let (mut off, mut on) = (Canvas::with_invert(false, false), Canvas::with_invert(false, true));
let (a, b, _) = off.gesture(wheel(MouseWheelUnit::Line, 3.0, mods), mods);
let (c, d, _) = on.gesture(wheel(MouseWheelUnit::Line, 3.0, mods), mods);
assert!(b.0 > a.0 * 1.05, "{mods:?} off zooms in: {a:?} -> {b:?}");
assert!(d.0 < c.0 / 1.05, "{mods:?} on zooms out: {c:?} -> {d:?}");
assert!(((b.0 / a.0) * (d.0 / c.0) - 1.0).abs() < 1e-3, "{mods:?} by the same factor");
}
}
#[test]
@@ -150,18 +152,33 @@ fn invert_zoom_reverses_a_plain_mouse_wheel_with_scroll_wheel_zoom_on() {
assert!(b.0 > a.0 * 1.05, "off zooms in: {a:?} -> {b:?}");
assert!(d.0 < c.0 / 1.05, "on zooms out: {c:?} -> {d:?}");
assert!(((b.0 / a.0) * (d.0 / c.0) - 1.0).abs() < 1e-3, "by the same factor");
// Without Scroll wheel zoom a plain wheel still scrolls, inverted or not.
let mut plain = Canvas::with_invert(false, true);
let (a, b, _) = plain.gesture(wheel(MouseWheelUnit::Line, -3.0, Modifiers::NONE), Modifiers::NONE);
assert!((b.0 - a.0).abs() < 1e-9 && b.2 > a.2 + 1.0, "scrolls: {a:?} -> {b:?}");
}
/// Panning is never inverted: the scroll vector is the same with the preference on and off.
#[test]
fn invert_zoom_leaves_panning_unchanged() {
// (Scroll wheel zoom, modifiers): a plain wheel without it, Cmd/Ctrl+wheel with it, Shift+wheel.
for (swz, mods) in [(false, Modifiers::NONE), (true, Modifiers::COMMAND), (true, Modifiers::CTRL), (true, Modifiers::SHIFT)] {
let (mut off, mut on) = (Canvas::with_invert(swz, false), Canvas::with_invert(swz, true));
let (a, b, _) = off.gesture(wheel(MouseWheelUnit::Line, -3.0, mods), mods);
let (c, d, _) = on.gesture(wheel(MouseWheelUnit::Line, -3.0, mods), mods);
assert!((b.0 - a.0).abs() < 1e-9 && (d.0 - c.0).abs() < 1e-9, "{mods:?} no zoom");
assert!(b.1 != a.1 || b.2 != a.2, "{mods:?} off pans: {a:?} -> {b:?}");
assert!(
((b.1 - a.1) - (d.1 - c.1)).abs() < 1e-9 && ((b.2 - a.2) - (d.2 - c.2)).abs() < 1e-9,
"{mods:?} same pan: {a:?} -> {b:?} vs {c:?} -> {d:?}"
);
}
}
#[test]
fn a_pinch_zooms_the_same_with_invert_zoom_on_and_off() {
for invert in [false, true] {
let mut c = Canvas::with_invert(false, invert);
let (a, b, _) = c.gesture(Event::Zoom(1.5), Modifiers::NONE);
assert!((b.0 / a.0 - 1.5).abs() < 1e-3, "invert {invert}: {a:?} -> {b:?}");
for (swz, invert, factor) in
[(false, false, 1.5), (false, true, 1.5), (true, false, 1.5), (true, true, 1.5), (true, true, 0.5), (false, true, 0.5)]
{
let mut c = Canvas::with_invert(swz, invert);
let (a, b, _) = c.gesture(Event::Zoom(factor), Modifiers::NONE);
assert!((b.0 / a.0 - f64::from(factor)).abs() < 1e-3, "scroll wheel zoom {swz}, invert {invert}, x{factor}: {a:?} -> {b:?}");
}
}