tbolis / react-sketch

Sketch Tool for React-based applications, backed up by FabricJS
http://tbolis.github.io/showcase/react-sketch/
MIT License
680 stars 230 forks source link

Copypaste tool #92

Closed mnsdanwater closed 4 years ago

mnsdanwater commented 4 years ago

When user choose Select tool and click copypaste button, it produce error below. How to check an object actually selected before enabling copypaste button? This error also occured on live showcase.

Error log Uncaught TypeError: Cannot read property 'clone' of null at SketchField.t.copy (index.js:16) at onClick (index.js:45) at Object.<anonymous> (index.js:37) at d (index.js:37) at index.js:37 at x (index.js:37) at O (index.js:37) at B (index.js:37) at M (index.js:37) at En (index.js:37)

hsluoyz commented 4 years ago

+1

hsluoyz commented 4 years ago

I found a solution:

  isSelected() {
    if (this.sketch._fc === undefined) {
      return true;
    }

    const obj = this.sketch._fc.getActiveObject();
    return obj !== undefined && obj !== null;
  }
mnsdanwater commented 4 years ago

I found a solution:

  isSelected() {
    if (this.sketch._fc === undefined) {
      return true;
    }

    const obj = this.sketch._fc.getActiveObject();
    return obj !== undefined && obj !== null;
  }

it works! thank you for your help :)