fix: improve canvas search scroll behavior further (#8491)

This commit is contained in:
David Luzar 2024-09-11 18:01:18 +02:00 committed by GitHub
parent b46ca0192b
commit fd39712ba6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 165 additions and 99 deletions

View file

@ -1,4 +1,4 @@
import type { AppState, PointerCoords, Zoom } from "../types";
import type { AppState, Offsets, PointerCoords, Zoom } from "../types";
import type { ExcalidrawElement } from "../element/types";
import {
getCommonBounds,
@ -31,14 +31,28 @@ export const centerScrollOn = ({
scenePoint,
viewportDimensions,
zoom,
offsets,
}: {
scenePoint: PointerCoords;
viewportDimensions: { height: number; width: number };
zoom: Zoom;
offsets?: Offsets;
}) => {
let scrollX =
(viewportDimensions.width - (offsets?.right ?? 0)) / 2 / zoom.value -
scenePoint.x;
scrollX += (offsets?.left ?? 0) / 2 / zoom.value;
let scrollY =
(viewportDimensions.height - (offsets?.bottom ?? 0)) / 2 / zoom.value -
scenePoint.y;
scrollY += (offsets?.top ?? 0) / 2 / zoom.value;
return {
scrollX: viewportDimensions.width / 2 / zoom.value - scenePoint.x,
scrollY: viewportDimensions.height / 2 / zoom.value - scenePoint.y,
scrollX,
scrollY,
};
};