From 0b424c31ec0e411fb88cb507659324d74d5d6d25 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Tue, 16 Feb 2021 08:38:40 +1100 Subject: [PATCH] Added delete shortcut to remove last point from polygon fog --- src/components/map/MapFog.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/components/map/MapFog.js b/src/components/map/MapFog.js index 39435c5..2695dc1 100644 --- a/src/components/map/MapFog.js +++ b/src/components/map/MapFog.js @@ -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);