Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(chat): an image preview zooms in only with the pointer over the picture

Absterrg0c10c607b1795
diff --git a/src/components/AttachmentPreview.test.ts b/src/components/AttachmentPreview.test.ts
index 3fbfc11c5d..97e950e3bb 100644
--- a/src/components/AttachmentPreview.test.ts
+++ b/src/components/AttachmentPreview.test.ts
@@ -406,6 +406,13 @@ describe("image preview wheel", () => {
expect((await wheel(-200, document.querySelector("[role=dialog] header")!)).defaultPrevented).toBe(true);
expect(picture().style.transform).toBe("");
+ const beside = picture().parentElement!;
+ expect((await wheel(-200, beside)).defaultPrevented).toBe(true);
+ expect(picture().style.transform).toBe("");
+ await wheel(-200);
+ await wheel(400, beside);
+ expect(picture().style.transform).toBe("");
+
await wheel(-200);
await act(async () => { window.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowRight" })); });
expect(picture().alt).toBe("next.png");
diff --git a/src/components/preview-zoom.ts b/src/components/preview-zoom.ts
index ee59fec009..d421bf3418 100644
--- a/src/components/preview-zoom.ts
+++ b/src/components/preview-zoom.ts
@@ -35,10 +35,11 @@ export function usePreviewZoom() {
event.stopPropagation();
const area = stage.current;
const picture = image.current;
- if (!area || !picture || event.deltaY === 0 || !area.contains(event.target as Node)) return;
+ if (!area || !picture || !area.contains(event.target as Node)) return;
+ const deltaY = wheelPixels(event, area.clientHeight);
+ if (deltaY === 0 || (deltaY < 0 && event.target !== picture)) return;
const box = area.getBoundingClientRect();
const point = { x: event.clientX - box.left - picture.offsetLeft, y: event.clientY - box.top - picture.offsetTop };
- const deltaY = wheelPixels(event, area.clientHeight);
setZoom((current) => zoomAtPoint(current, deltaY, point));
};
element.addEventListener("wheel", onWheel, { passive: false });