Skip to content

Commit

Permalink
Clipping plane anchor button fix on escape (#227)
Browse files Browse the repository at this point in the history
Currently when you press esc while moving clipping plane with on-screen scissors button - you can end up in the broken state
  • Loading branch information
nd-novorender authored Dec 5, 2024
1 parent 8c15d32 commit 27d3b6f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/features/clippingPlanes/useClippingPlaneActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ export function useClippingPlaneActions() {
const normalOffset = originalNormalOffset;
const anchorPos = originalAnchorPos;

const anchor = document.querySelector(`#${getClippingPlaneAnchorId(idx)}`) as HTMLElement;
const anchor = document.querySelector(`#${getClippingPlaneAnchorId(idx)}`) as
| HTMLElement
| undefined;
const offsetNode = anchor?.querySelector(`[data-offset]`) as HTMLElement;

return {
Expand Down Expand Up @@ -178,8 +180,6 @@ export function useClippingPlaneActions() {
offsetNode.innerText = text;
}
}

return editedPlane;
});

view.modifyRenderState({
Expand Down Expand Up @@ -231,17 +231,18 @@ export function useClippingPlaneActions() {
planes: planes.slice(),
}),
);
moveCameraToPlane(0);
}

if (cameraType === CameraType.Orthographic) {
dispatch(renderActions.setClippingInEdit(false));
}

for (const { offsetNode, anchor, anchorPos } of editedPlanes) {
if (anchorPos) {
for (const { offsetNode, anchor, anchorPos, originalAnchorPos2d } of editedPlanes) {
if (anchor && anchorPos) {
offsetNode?.style.setProperty("display", "none");

const pos2d = getAnchorPos2d(view!, [anchorPos])[0];
const pos2d = save ? getAnchorPos2d(view!, [anchorPos])[0] : originalAnchorPos2d;
if (pos2d) {
anchor.style.setProperty("left", `${pos2d[0]}px`);
anchor.style.setProperty("top", `${pos2d[1]}px`);
Expand Down

0 comments on commit 27d3b6f

Please sign in to comment.