This commit is contained in:
barnabasmolnar
2026-04-07 23:44:27 +02:00
parent 7dbd62a30c
commit fe3ba884f6
3 changed files with 24 additions and 18 deletions
@@ -4,9 +4,10 @@ import { Excalidraw } from "@excalidraw/excalidraw";
import "@excalidraw/excalidraw/index.css";
import App from "../../with-script-in-browser/components/ExampleApp";
import type { ScrollConstraints } from "@excalidraw/excalidraw/types";
import App from "../../with-script-in-browser/components/ExampleApp";
const scrollConstraints: ScrollConstraints = {
x: 0,
y: 0,
@@ -25,9 +26,7 @@ const ExcalidrawWrapper: React.FC = () => {
useCustom={(api: any, args?: any[]) => {}}
excalidrawLib={excalidrawLib}
>
<Excalidraw
// scrollConstraints={scrollConstraints}
/>
<Excalidraw scrollConstraints={scrollConstraints} />
</App>
</>
);
+9 -11
View File
@@ -4531,18 +4531,16 @@ class App extends React.Component<AppProps, AppState> {
this.setState({ shouldCacheIgnoreZoom: false });
},
});
} else if (scrollConstraints) {
this.setState({
scrollX,
scrollY,
zoom,
scrollConstraints,
viewModeEnabled: true,
});
} else {
if (scrollConstraints) {
this.setState({
scrollX,
scrollY,
zoom,
scrollConstraints,
viewModeEnabled: true,
});
} else {
this.setState({ scrollX, scrollY, zoom });
}
this.setState({ scrollX, scrollY, zoom });
}
};
+12 -3
View File
@@ -1,6 +1,7 @@
import type { AppState, NormalizedZoomValue } from "../types";
import { constrainScrollState } from "./scrollConstraints";
import type { AppState, NormalizedZoomValue } from "../types";
/**
* When zooming out with scroll constraints active, the cursor-anchored zoom may
* produce a scroll position outside the valid bounds, causing a snap-back.
@@ -30,11 +31,19 @@ export const getConstrainedZoomAnchor = (
const newScrollY = state.scrollY + appLayerY * factor;
const constrained = constrainScrollState(
{ ...state, scrollX: newScrollX, scrollY: newScrollY, zoom: { value: nextZoom } },
{
...state,
scrollX: newScrollX,
scrollY: newScrollY,
zoom: { value: nextZoom },
},
"rigid",
);
if (constrained.scrollX === newScrollX && constrained.scrollY === newScrollY) {
if (
constrained.scrollX === newScrollX &&
constrained.scrollY === newScrollY
) {
return { viewportX, viewportY };
}