Automatically select last inserted element

This commit is contained in:
Christopher Chedeau 2020-01-01 21:10:56 -08:00
parent c26d04e162
commit 2fa00f39fc

View File

@ -219,6 +219,9 @@ function App() {
id="canvas" id="canvas"
width={window.innerWidth} width={window.innerWidth}
height={window.innerHeight} height={window.innerHeight}
onClick={e => {
console.log("click");
}}
onMouseDown={e => { onMouseDown={e => {
const x = e.clientX - e.target.offsetLeft; const x = e.clientX - e.target.offsetLeft;
const y = e.clientY - e.target.offsetTop; const y = e.clientY - e.target.offsetTop;
@ -255,12 +258,14 @@ function App() {
drawScene(); drawScene();
}} }}
onMouseUp={e => { onMouseUp={e => {
setDraggingElement(null);
if (elementType === "selection") { if (elementType === "selection") {
// Remove actual selection element // Remove actual selection element
elements.pop(); elements.pop();
setSelection(draggingElement); setSelection(draggingElement);
} else {
draggingElement.isSelected = true;
} }
setDraggingElement(null);
setElementType("selection"); setElementType("selection");
drawScene(); drawScene();
}} }}