Added delete shortcut to remove last point from polygon fog

This commit is contained in:
Mitchell McCaffrey
2021-02-16 08:38:40 +11:00
parent 7639297510
commit 0b424c31ec
+22
View File
@@ -402,6 +402,28 @@ function MapFog({
if (key === "Escape" && drawingShape) {
setDrawingShape(null);
}
// Remove last point from polygon shape if delete pressed
if (
(key === "Backspace" || key === "Delete") &&
drawingShape &&
toolSettings.type === "polygon"
) {
if (drawingShape.data.points.length > 2) {
setDrawingShape((drawingShape) => ({
...drawingShape,
data: {
...drawingShape.data,
points: [
// Shift last point to previous point
...drawingShape.data.points.slice(0, -2),
...drawingShape.data.points.slice(-1),
],
},
}));
} else {
setDrawingShape(null);
}
}
}
useKeyboard(handleKeyDown);