Skip to content

Commit

Permalink
Fixed hide transformer in a better way
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivanruii committed Aug 6, 2024
1 parent fbcbf22 commit cfaaae5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 11 additions & 2 deletions src/core/providers/canvas/use-selection.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@ export const useSelection = (
null
);

// Remove unused shapes
// Remove unused shapes and reset selectedShapeId if it no longer exists
useEffect(() => {
const currentIds = shapes.map(shape => shape.id);

Object.keys(shapeRefs.current).forEach(id => {
if (!currentIds.includes(id)) {
delete shapeRefs.current[id];
}
});
}, [shapes]);

if (!currentIds.includes(selectedShapeId)) {
transformerRef.current?.nodes([]);
selectedShapeRef.current = null;
setSelectedShapeId('');
setSelectedShapeType(null);
}
}, [shapes, selectedShapeId]);

const handleSelected = (id: string, type: ShapeType) => {
selectedShapeRef.current = shapeRefs.current[id].current;
Expand All @@ -42,6 +50,7 @@ export const useSelection = (
transformerRef.current?.nodes([]);
selectedShapeRef.current = null;
setSelectedShapeId('');
setSelectedShapeType(null);
}
};

Expand Down
5 changes: 0 additions & 5 deletions src/pods/canvas/canvas.pod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ export const CanvasPod = () => {
};
}, [selectedShapeId]);

useEffect(() => {
transformerRef.current?.nodes([]);
selectedShapeRef.current = null;
}, [shapes]);

{
/* TODO: add other animation for isDraggerOver */
}
Expand Down

0 comments on commit cfaaae5

Please sign in to comment.