From 6f4bd85e1c0ef042385d0b88634add5dd3502660 Mon Sep 17 00:00:00 2001 From: rsdexter Date: Mon, 27 Apr 2020 14:40:07 -0400 Subject: [PATCH] erasure deletes the selection properly when given the ID and creates a new step --- src/canvas/Canvas.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/canvas/Canvas.js b/src/canvas/Canvas.js index 1b8b204..27a1f20 100644 --- a/src/canvas/Canvas.js +++ b/src/canvas/Canvas.js @@ -86,6 +86,15 @@ class Canvas extends React.Component { }, erase: (id) => { console.log("ERASURE") + let successful = this.erasure(id); + if (successful) + this.setState({ + highlights: { + cut: 'none', + var: 'none' + }, + interaction: true, + cbFunction: null }); }, iterate: (id) => { console.log("ITERATION") @@ -131,6 +140,38 @@ class Canvas extends React.Component { }); } + erasure(id) { + let { steps, currentStep, data } = this.state; + // Create a new step + let step = this.copyStep(steps[currentStep]); + // Find the data that will be erased + let erased = this.findID(step, id); + console.log(erased) + if (!erased) { + console.log("Selection ID not found for Erasure.") + return false; + } + // Get the parent of the erased section + let parent = this.findParent(step, id) + if (!parent) { + console.log("Parent of ID not found for Erasure.") + return false; + } + // Remove the erased data from the parent's data array + const index = parent.data.indexOf(erased); + if (index > -1) + parent.data.splice(index, 1); + else { + console.log("Selection not found under its parent.") + return false; + } + // Update the state + currentStep+=1; + steps.push(step); + this.setState({ steps: steps, currentStep: currentStep, data:data }); + return true; + } + /* Adds a double cut given the ID of the data that will be inside the cut. * Will only run if the current step is the last step. */ -- 2.51.2