fix scrollToCenter when no elements supplied (#1222)
* fix scrollToCenter when no elements supplied * make getCommonBounds return default values on empty elements
This commit is contained in:
parent
b97520400a
commit
4dd947b261
@ -187,6 +187,10 @@ export function getArrowPoints(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getCommonBounds(elements: readonly ExcalidrawElement[]) {
|
export function getCommonBounds(elements: readonly ExcalidrawElement[]) {
|
||||||
|
if (!elements.length) {
|
||||||
|
return [0, 0, 0, 0];
|
||||||
|
}
|
||||||
|
|
||||||
let minX = Infinity;
|
let minX = Infinity;
|
||||||
let maxX = -Infinity;
|
let maxX = -Infinity;
|
||||||
let minY = Infinity;
|
let minY = Infinity;
|
||||||
|
@ -9,6 +9,13 @@ export function normalizeScroll(pos: number) {
|
|||||||
export function calculateScrollCenter(
|
export function calculateScrollCenter(
|
||||||
elements: readonly ExcalidrawElement[],
|
elements: readonly ExcalidrawElement[],
|
||||||
): { scrollX: FlooredNumber; scrollY: FlooredNumber } {
|
): { scrollX: FlooredNumber; scrollY: FlooredNumber } {
|
||||||
|
if (!elements.length) {
|
||||||
|
return {
|
||||||
|
scrollX: normalizeScroll(0),
|
||||||
|
scrollY: normalizeScroll(0),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const [x1, y1, x2, y2] = getCommonBounds(elements);
|
const [x1, y1, x2, y2] = getCommonBounds(elements);
|
||||||
|
|
||||||
const centerX = (x1 + x2) / 2;
|
const centerX = (x1 + x2) / 2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user