From c26d04e162f9a70dae56ec15dfe4f0f6f544c3de Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Wed, 1 Jan 2020 21:03:44 -0800 Subject: [PATCH] Don't write null when cancelling text --- src/index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 8b31f0c1..30b3e224 100644 --- a/src/index.js +++ b/src/index.js @@ -30,7 +30,7 @@ function rotate(x1, y1, x2, y2, angle) { var generator = rough.generator(); -function generateShape(element) { +function generateDraw(element) { if (element.type === "selection") { element.draw = (rc, context) => { const fillStyle = context.fillStyle; @@ -225,7 +225,11 @@ function App() { const element = newElement(elementType, x, y); if (elementType === "text") { - element.text = prompt("What text do you want?"); + const text = prompt("What text do you want?"); + if (text === null) { + return; + } + element.text = text; element.font = "20px Virgil"; const font = context.font; context.font = element.font; @@ -241,7 +245,7 @@ function App() { element.height = height; } - generateShape(element); + generateDraw(element); elements.push(element); if (elementType === "text") { setDraggingElement(null); @@ -268,7 +272,7 @@ function App() { // Make a perfect square or circle when shift is enabled draggingElement.height = e.shiftKey ? width : height; - generateShape(draggingElement); + generateDraw(draggingElement); if (elementType === "selection") { setSelection(draggingElement);