@@ -214,8 +214,6 @@ const getTargetViewport = (
|
|||||||
targetElements: readonly ExcalidrawElement[],
|
targetElements: readonly ExcalidrawElement[],
|
||||||
opts?: ScrollToContentOptions,
|
opts?: ScrollToContentOptions,
|
||||||
): Viewport => {
|
): Viewport => {
|
||||||
let viewport: Viewport;
|
|
||||||
|
|
||||||
if (opts?.fitToContent || opts?.fitToViewport) {
|
if (opts?.fitToContent || opts?.fitToViewport) {
|
||||||
const { appState } = zoomToFit({
|
const { appState } = zoomToFit({
|
||||||
canvasOffsets: opts.canvasOffsets,
|
canvasOffsets: opts.canvasOffsets,
|
||||||
@@ -227,19 +225,16 @@ const getTargetViewport = (
|
|||||||
maxZoom: opts.maxZoom,
|
maxZoom: opts.maxZoom,
|
||||||
});
|
});
|
||||||
|
|
||||||
viewport = {
|
return {
|
||||||
scrollX: appState.scrollX,
|
scrollX: appState.scrollX,
|
||||||
scrollY: appState.scrollY,
|
scrollY: appState.scrollY,
|
||||||
zoom: appState.zoom,
|
zoom: appState.zoom,
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
// keep the current zoom, only recenter the viewport on the target
|
|
||||||
const { scrollX, scrollY } = calculateScrollCenter(targetElements, state);
|
|
||||||
viewport = { scrollX, scrollY, zoom: state.zoom };
|
|
||||||
}
|
}
|
||||||
|
// keep the current zoom, only recenter the viewport on the target
|
||||||
|
const { scrollX, scrollY } = calculateScrollCenter(targetElements, state);
|
||||||
|
|
||||||
// keep programmatic scrolling within the constraint box, if any
|
return { scrollX, scrollY, zoom: state.zoom };
|
||||||
return constrainScrollState({ ...state, ...viewport });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -310,9 +305,6 @@ const animateToViewport = (
|
|||||||
shouldCacheIgnoreZoom: progress < 1, // ignore zoom caching while animating
|
shouldCacheIgnoreZoom: progress < 1, // ignore zoom caching while animating
|
||||||
});
|
});
|
||||||
|
|
||||||
// returning a falsy value signals the AnimationController to remove the
|
|
||||||
// animation; otherwise it would keep ticking (and calling onFrame) every
|
|
||||||
// frame forever after reaching the target
|
|
||||||
return progress < 1 ? { elapsed } : null;
|
return progress < 1 ? { elapsed } : null;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user