Skip to content

Commit

Permalink
fix: avoid deleting all entities when pressing escape
Browse files Browse the repository at this point in the history
  • Loading branch information
bertyhell committed Aug 10, 2024
1 parent 28a1f71 commit 12e14b9
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ function App() {

console.log('Set active entity to null');
setActiveEntity(null);
return newEntities;
}
return newEntities;
});
Expand Down Expand Up @@ -285,18 +284,29 @@ function App() {
});
}, []);

const deSelectAndDeHighlightEntities = useCallback(
(entitiesTemp: Entity[]): Entity[] => {
return entitiesTemp.map(entity => {
entity.isHighlighted = false;
entity.isSelected = false;
return entity;
});
},
[],
);

const handleKeyUp = useCallback(
(evt: KeyboardEvent) => {
if (evt.key === 'Escape') {
setActiveEntity(null);
setEntities(deSelectEntities(deHighlightEntities(entities)));
setEntities(oldEntities => deSelectAndDeHighlightEntities(oldEntities));
} else if (evt.key === 'Delete') {
setEntities(oldEntities =>
oldEntities.filter(entity => !entity.isSelected),
);
}
},
[deHighlightEntities, deSelectEntities, entities],
[deSelectAndDeHighlightEntities],
);

const handleToolClick = useCallback(
Expand Down Expand Up @@ -487,7 +497,7 @@ function App() {
useEffect(() => {
const watchSnapPointTimerId = setInterval(() => {
watchSnapPoint();
}, 1000);
}, 100);
return () => {
clearInterval(watchSnapPointTimerId);
};
Expand Down

0 comments on commit 12e14b9

Please sign in to comment.