From 2d66616e3f01e17db674063a2a42e9650fd01cb3 Mon Sep 17 00:00:00 2001 From: Timur Khazamov Date: Tue, 7 Jan 2020 23:02:15 +0500 Subject: [PATCH] Fixed: Copy + Paste moves text inside rectangle #229 (#245) --- src/index.tsx | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 1ab5c975..c2499785 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1010,20 +1010,16 @@ class App extends React.Component<{}, AppState> { ) { clearSelection(elements); - let dx: number; - let dy: number; - if (x) { - let minX = Math.min(...parsedElements.map(element => element.x)); - dx = x - minX; - } - if (y) { - let minY = Math.min(...parsedElements.map(element => element.y)); - dy = y - minY; - } + if (x == null) x = 10 - this.state.scrollX; + if (y == null) y = 10 - this.state.scrollY; + const minX = Math.min(...parsedElements.map(element => element.x)); + const minY = Math.min(...parsedElements.map(element => element.y)); + const dx = x - minX; + const dy = y - minY; parsedElements.forEach(parsedElement => { - parsedElement.x = dx ? parsedElement.x + dx : 10 - this.state.scrollX; - parsedElement.y = dy ? parsedElement.y + dy : 10 - this.state.scrollY; + parsedElement.x += dx; + parsedElement.y += dy; parsedElement.seed = randomSeed(); elements.push(parsedElement); });