fix: scrollToContent only on visible elements (#3466)
This commit is contained in:
parent
87c42cb327
commit
6730eb41c2
@ -78,7 +78,6 @@ import {
|
|||||||
getCursorForResizingElement,
|
getCursorForResizingElement,
|
||||||
getDragOffsetXY,
|
getDragOffsetXY,
|
||||||
getElementWithTransformHandleType,
|
getElementWithTransformHandleType,
|
||||||
getNonDeletedElements,
|
|
||||||
getNormalizedDimensions,
|
getNormalizedDimensions,
|
||||||
getPerfectElementSize,
|
getPerfectElementSize,
|
||||||
getResizeArrowDirection,
|
getResizeArrowDirection,
|
||||||
@ -1402,11 +1401,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
setScrollToContent = (remoteElements: readonly ExcalidrawElement[]) => {
|
setScrollToContent = (remoteElements: readonly ExcalidrawElement[]) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
...calculateScrollCenter(
|
...calculateScrollCenter(remoteElements, this.state, this.canvas),
|
||||||
getNonDeletedElements(remoteElements),
|
|
||||||
this.state,
|
|
||||||
this.canvas,
|
|
||||||
),
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -77,6 +77,11 @@ export const getElementMap = (elements: readonly ExcalidrawElement[]) =>
|
|||||||
export const getSceneVersion = (elements: readonly ExcalidrawElement[]) =>
|
export const getSceneVersion = (elements: readonly ExcalidrawElement[]) =>
|
||||||
elements.reduce((acc, el) => acc + el.version, 0);
|
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[]) =>
|
export const getNonDeletedElements = (elements: readonly ExcalidrawElement[]) =>
|
||||||
elements.filter(
|
elements.filter(
|
||||||
(element) => !element.isDeleted,
|
(element) => !element.isDeleted,
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
import { AppState, PointerCoords, Zoom } from "../types";
|
import { AppState, PointerCoords, Zoom } from "../types";
|
||||||
import { ExcalidrawElement } from "../element/types";
|
import { ExcalidrawElement } from "../element/types";
|
||||||
import { getCommonBounds, getClosestElementBounds } from "../element";
|
import {
|
||||||
|
getCommonBounds,
|
||||||
|
getClosestElementBounds,
|
||||||
|
getVisibleElements,
|
||||||
|
} from "../element";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
sceneCoordsToViewportCoords,
|
sceneCoordsToViewportCoords,
|
||||||
@ -53,6 +57,8 @@ export const calculateScrollCenter = (
|
|||||||
appState: AppState,
|
appState: AppState,
|
||||||
canvas: HTMLCanvasElement | null,
|
canvas: HTMLCanvasElement | null,
|
||||||
): { scrollX: number; scrollY: number } => {
|
): { scrollX: number; scrollY: number } => {
|
||||||
|
elements = getVisibleElements(elements);
|
||||||
|
|
||||||
if (!elements.length) {
|
if (!elements.length) {
|
||||||
return {
|
return {
|
||||||
scrollX: 0,
|
scrollX: 0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user