mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: stop flooring scroll positions (#2883)
This commit is contained in:
parent
10cd6a24b0
commit
1973ae9444
10 changed files with 41 additions and 58 deletions
|
@ -1,4 +1,4 @@
|
|||
import { AppState, FlooredNumber, PointerCoords, Zoom } from "../types";
|
||||
import { AppState, PointerCoords, Zoom } from "../types";
|
||||
import { ExcalidrawElement } from "../element/types";
|
||||
import { getCommonBounds, getClosestElementBounds } from "../element";
|
||||
|
||||
|
@ -7,9 +7,6 @@ import {
|
|||
viewportCoordsToSceneCoords,
|
||||
} from "../utils";
|
||||
|
||||
export const normalizeScroll = (pos: number) =>
|
||||
Math.floor(pos) as FlooredNumber;
|
||||
|
||||
const isOutsideViewPort = (
|
||||
appState: AppState,
|
||||
canvas: HTMLCanvasElement | null,
|
||||
|
@ -40,16 +37,14 @@ export const centerScrollOn = ({
|
|||
zoom: Zoom;
|
||||
}) => {
|
||||
return {
|
||||
scrollX: normalizeScroll(
|
||||
scrollX:
|
||||
(viewportDimensions.width / 2) * (1 / zoom.value) -
|
||||
scenePoint.x -
|
||||
zoom.translation.x * (1 / zoom.value),
|
||||
),
|
||||
scrollY: normalizeScroll(
|
||||
scenePoint.x -
|
||||
zoom.translation.x * (1 / zoom.value),
|
||||
scrollY:
|
||||
(viewportDimensions.height / 2) * (1 / zoom.value) -
|
||||
scenePoint.y -
|
||||
zoom.translation.y * (1 / zoom.value),
|
||||
),
|
||||
scenePoint.y -
|
||||
zoom.translation.y * (1 / zoom.value),
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -57,11 +52,11 @@ export const calculateScrollCenter = (
|
|||
elements: readonly ExcalidrawElement[],
|
||||
appState: AppState,
|
||||
canvas: HTMLCanvasElement | null,
|
||||
): { scrollX: FlooredNumber; scrollY: FlooredNumber } => {
|
||||
): { scrollX: number; scrollY: number } => {
|
||||
if (!elements.length) {
|
||||
return {
|
||||
scrollX: normalizeScroll(0),
|
||||
scrollY: normalizeScroll(0),
|
||||
scrollX: 0,
|
||||
scrollY: 0,
|
||||
};
|
||||
}
|
||||
let [x1, y1, x2, y2] = getCommonBounds(elements);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue