fix: scrollToContent only on visible elements (#3466)

This commit is contained in:
David Luzar 2021-04-19 17:29:13 +02:00 committed by GitHub
parent 87c42cb327
commit 6730eb41c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 7 deletions

View File

@ -78,7 +78,6 @@ import {
getCursorForResizingElement,
getDragOffsetXY,
getElementWithTransformHandleType,
getNonDeletedElements,
getNormalizedDimensions,
getPerfectElementSize,
getResizeArrowDirection,
@ -1402,11 +1401,7 @@ class App extends React.Component<AppProps, AppState> {
setScrollToContent = (remoteElements: readonly ExcalidrawElement[]) => {
this.setState({
...calculateScrollCenter(
getNonDeletedElements(remoteElements),
this.state,
this.canvas,
),
...calculateScrollCenter(remoteElements, this.state, this.canvas),
});
};

View File

@ -77,6 +77,11 @@ export const getElementMap = (elements: readonly ExcalidrawElement[]) =>
export const getSceneVersion = (elements: readonly ExcalidrawElement[]) =>
elements.reduce((acc, el) => acc + el.version, 0);
export const getVisibleElements = (elements: readonly ExcalidrawElement[]) =>
elements.filter(
(el) => !el.isDeleted && !isInvisiblySmallElement(el),
) as readonly NonDeletedExcalidrawElement[];
export const getNonDeletedElements = (elements: readonly ExcalidrawElement[]) =>
elements.filter(
(element) => !element.isDeleted,

View File

@ -1,6 +1,10 @@
import { AppState, PointerCoords, Zoom } from "../types";
import { ExcalidrawElement } from "../element/types";
import { getCommonBounds, getClosestElementBounds } from "../element";
import {
getCommonBounds,
getClosestElementBounds,
getVisibleElements,
} from "../element";
import {
sceneCoordsToViewportCoords,
@ -53,6 +57,8 @@ export const calculateScrollCenter = (
appState: AppState,
canvas: HTMLCanvasElement | null,
): { scrollX: number; scrollY: number } => {
elements = getVisibleElements(elements);
if (!elements.length) {
return {
scrollX: 0,