Handle backspace

This commit is contained in:
Christopher Chedeau 2020-01-01 17:58:28 -08:00
parent 9dc19dde1d
commit 3769c4af00

View File

@ -117,6 +117,23 @@ function setSelection(selection) {
function App() { function App() {
const [draggingElement, setDraggingElement] = React.useState(null); const [draggingElement, setDraggingElement] = React.useState(null);
const [elementType, setElementType] = React.useState("selection"); const [elementType, setElementType] = React.useState("selection");
const onKeyDown = React.useCallback(event => {
if (event.key === "Backspace") {
for (var i = elements.length - 1; i >= 0; --i) {
if (elements[i].isSelected) {
elements.splice(i, 1);
}
}
drawScene();
}
}, []);
React.useEffect(() => {
document.addEventListener("keydown", onKeyDown, false);
return () => {
document.removeEventListener("keydown", onKeyDown, false);
};
}, [onKeyDown]);
function ElementOption({ type, children }) { function ElementOption({ type, children }) {
return ( return (
<label> <label>