mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
WebViews don't expose macOS momentum phases, so a trackpad scroll still coasting when ⌘ was pressed zoomed the text, and the inertia after a ⌘ swipe kept zooming. Wheel events less than 150 ms apart now count as one gesture: only a gesture that started with ⌘/Ctrl zooms, and once its deltas shrink four events in a row the rest is inertia. All ⌘/Ctrl+wheel font-zoom surfaces use it (editor, terminal, agent chat, Markdown preview, plugin and services log editors). Co-authored-by: pravdomil <2387356+pravdomil@users.noreply.github.com>
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { beforeEach, describe, expect, it } from "vitest";
|
|
import { resetWheelZoomGesture, wheelZoomStep } from "./wheelZoom";
|
|
|
|
let t = 0;
|
|
const wheel = (deltaY: number, mod = true, gap = 16) => {
|
|
t += gap;
|
|
return wheelZoomStep({ deltaY, metaKey: mod, ctrlKey: false, timeStamp: t });
|
|
};
|
|
|
|
describe("wheelZoomStep", () => {
|
|
beforeEach(() => {
|
|
resetWheelZoomGesture();
|
|
t = 1000;
|
|
});
|
|
|
|
it("zooms in and out with ⌘ held from the start of the gesture", () => {
|
|
expect(wheel(-4)).toBe(1);
|
|
expect(wheel(-6)).toBe(1);
|
|
expect(wheel(10, true, 500)).toBe(-1);
|
|
});
|
|
|
|
it("leaves plain scrolling alone", () => {
|
|
expect(wheel(-10, false)).toBeNull();
|
|
});
|
|
|
|
it("keeps scrolling the inertia of a plain scroll when ⌘ is pressed during it", () => {
|
|
expect(wheel(-40, false)).toBeNull();
|
|
expect(wheel(-30)).toBeNull();
|
|
expect(wheel(-20)).toBeNull();
|
|
expect(wheel(-10, true, 500)).toBe(1);
|
|
});
|
|
|
|
it("stops zooming once the deltas decay like inertia, without scrolling", () => {
|
|
for (const d of [-8, -12, -15]) expect(wheel(d)).toBe(1);
|
|
expect(wheel(-14)).toBe(1);
|
|
expect(wheel(-12)).toBe(1);
|
|
expect(wheel(-9)).toBe(1);
|
|
expect(wheel(-6)).toBe(0);
|
|
expect(wheel(-4)).toBe(0);
|
|
expect(wheel(-5)).toBe(0);
|
|
});
|
|
|
|
it("never swallows a plain wheel event, even during a zoom gesture", () => {
|
|
expect(wheel(-10)).toBe(1);
|
|
expect(wheel(-10, false)).toBeNull();
|
|
});
|
|
|
|
it("gives the same answer for repeated calls with one event", () => {
|
|
const e = { deltaY: -10, metaKey: true, ctrlKey: false, timeStamp: 5000 };
|
|
expect(wheelZoomStep(e)).toBe(1);
|
|
expect(wheelZoomStep(e)).toBe(1);
|
|
});
|
|
});
|