From 2689203391f5dbd6c9fc8319ec99c178f4436515 Mon Sep 17 00:00:00 2001 From: Chris Vanderloo Date: Sat, 26 Sep 2020 23:00:51 -0400 Subject: [PATCH] fixed toggling off selection state --- src/canvas/Canvas.js | 74 ++++++++++++++++++++++++++-------------- src/canvas/Toolbox.js | 36 ++++++++++--------- src/canvas/manipulate.js | 55 ++++++++++++++++++++++++++++- 3 files changed, 121 insertions(+), 44 deletions(-) diff --git a/src/canvas/Canvas.js b/src/canvas/Canvas.js index 3bd0126..1520615 100644 --- a/src/canvas/Canvas.js +++ b/src/canvas/Canvas.js @@ -33,7 +33,6 @@ function initXY(step, level) { // in between two variables, so that we can evenly place // them initially across the screen function initXYRecurse(step, level, gapSize) { - console.log(data) for (let s in step) { if (step[s] instanceof Array && step[s].length > 0) { let id = nanoid() @@ -72,11 +71,12 @@ class Canvas extends React.Component { this.getSVGCoords = this.getSVGCoords.bind(this); this.highlightCut = this.highlightCut.bind(this); this.modifyCanvas = this.modifyCanvas.bind(this); + this.cancelSelection = this.cancelSelection.bind(this); + this.createElement = this.createElement.bind(this); this.getSelection = this.getSelection.bind(this); let { premises, conclusion, steps, data } = this.props.proof; - console.log(steps.length - 1) this.state = { proof: { premises: premises, @@ -100,7 +100,8 @@ class Canvas extends React.Component { erasure: () => manipulate(this).erasure(), iteration: () => manipulate(this).iteration(), doubleCutRemove: () => manipulate(this).doubleCutRemove(), - doubleCutAdd: () => manipulate(this).doubleCutAdd() + doubleCutEnclose: () => manipulate(this).doubleCutEnclose(), + doubleCutAdd: () => manipulate(this).doubleCutAdd(), } } } @@ -124,13 +125,15 @@ class Canvas extends React.Component { highlights: selectConfig, interaction: false, cbFunction: (id) => { - if (this.state.finishCB) + if (this.state.finishCB) { this.state.finishCB(); + } this.setState({ highlights: { cut: 'none', var: 'none' }, + finishCB: null, interaction: true, cbFunction: null }); resolve(id); @@ -145,24 +148,24 @@ class Canvas extends React.Component { changeHistory = changeHistory.slice() changeHistory.push({ steps: Array.from(steps) }); // okay, now we call the requested function from Toolbox - // - // cancel any previous actions - if (this.state.cbFunction) { - this.state.cbFunction(null); - } this.setState({ finishCB: finishedCb }, () => { this.state.functions[nameOfFunction]().then(state => { - if (state) { - // now we can apply the new changeHistory - this.setState({ - changeHistory: changeHistory, - redoHistory: [], - ...state }); - } + if (state) { + // now we can apply the new changeHistory + this.setState({ + changeHistory: changeHistory, + redoHistory: [], + ...state }); + } }); }); } + cancelSelection() { + let { cbFunction } = this.state; + if (cbFunction) cbFunction(); + } + changePos(id, x, y) { let { data } = this.state; Object.assign(data[id], { x: x, y: y }) @@ -187,6 +190,24 @@ class Canvas extends React.Component { return false; } + createElement(text, type, currentStep, x, y) { + let { data } = this.state; + let id = nanoid(); + data[id] = {}; + data[id].x = x || 0; + data[id].y = y || 0; + data[id].type = type; + data[id].var = text; + console.log(text,type,currentStep) + currentStep.push(id); + this.setState({ data }); + } + + removeElement(id) { + let { data, steps } = this.state; + steps[this.state.currentStep].push(id); + } + renderStep(stepIndex) { let { data } = this.state; let step = this.state.steps[stepIndex] @@ -200,13 +221,7 @@ class Canvas extends React.Component { const renderRecurse = (step) => { let jsx = []; if (step.length === 0) { - let id = nanoid(); - data[id] = {}; - setXY(id, 0, 0); - data[id].type = "emptyvar"; - data[id].var = "\xa0"; - step.push(id); - this.setState({ data: data }); + this.createElement("\xa0", "emptyvar", step, 0, 0); } for (let s in step) { if (step[s].type === "cut") { @@ -216,6 +231,7 @@ class Canvas extends React.Component { level={level} enableHighlight={this.highlightCut(level)} id={step[s].id} + key={step[s].id} selectedCallback={this.state.cbFunction}> {renderRecurse(step[s].data)} @@ -239,7 +255,7 @@ class Canvas extends React.Component { {el.var} ); - } else if (this.state.data[step[s]].type === "emptyvar") { + } else if (this.state.data[step[s]].type === "emptyvar" && step.length === 1) { let el = this.state.data[step[s]]; jsx.unshift(