ShaMan123 / erase2d

A simple erasing tool for canvas apps
https://shaman123.github.io/erase2d/
Other
16 stars 4 forks source link

How to do an undo on this eraser ? #47

Closed davidanquetin closed 2 weeks ago

davidanquetin commented 2 weeks ago

Hello I am searching how to do an Undo on an Eraser action ?

I tried

const eraser = new EraserBrush(myCanvas);
eraser.on('end', (e) => {
     setTimeout(()=>{
     myCanvas.remove(e.detail.path)
          //or tried eraser.inverted = true
     }, 2000)

but it seems not to be the good method. Is the path of Eraser similar to another canvas object ? It seems not to be in canvas.getObjects() ?..

thanks in advance

ShaMan123 commented 2 weeks ago

Checkout the readme. You should preventDefault and call commit yourself. That will return a record with the data you need. Then remove the paths from the object's clip path.

davidanquetin commented 2 weeks ago

Thanks ! I will check this documentation, which is unfortunately not clearly mentioned anywhere ..

davidanquetin commented 2 weeks ago

ok, my error was to not call canvas.renderAll() after deleting the target clipPath ! Thanks