0

I have two canvas objects (Rectungle and Triangle) in group. Then i need to delete them, then return one of objects to is past position.

Here is two objects and group

    var rect1 = new fabric.Rect(
{
id: 1, left: 10, top: 10, width: 100, height: 50, angle: 45, fill: 'red'
});
    var tria1 = new fabric.Triangle({
id: 2, left: 200, top: 200, width: 100, height: 50, angle: 20, fill: 'yellow'
});

var objsGroup = new fabric.Group([rect1, tria1], {left: 100, top: 100});

And the whole fiddle here. I separate all steps by alerts https://jsfiddle.net/5js60oec/

UPDATE

Have the next problem. Lets assume that existing object group making some move and rotating before deleting. Then i have to restore it to point before rotating and moving. Thats, i think the main problem.

Actions

objsGroup.top = 200;
objsGroup.left = 200;

canvas.renderAll();
alert('4');

history.push(canvas.getActiveGroup());

objsGroup.setAngle(45);

canvas.renderAll();

Here the full fiddler: https://jsfiddle.net/nppaLetn/1/

Yuri Molchanov
  • 131
  • 1
  • 1
  • 9
  • 1
    You may watch these answers in stackoverflow (http://stackoverflow.com/questions/22338080/undo-redo-history-for-canvas-fabricjs/23226432#23226432) – SakthiSureshAnand Nov 20 '15 at 11:52
  • @sakthi, thanks. But i trying to find the way to revert only an object but not all canvas. This way will work but its will be using alot of resourses on the client side ) – Yuri Molchanov Nov 20 '15 at 13:04

1 Answers1

0

For example I am deleting the last added path in my canvas like below

var lastItemIndex = (fabricCanvas.getObjects().length - 1);
var item = fabricCanvas.item(lastItemIndex);

if(item.get('type') === 'path') {
  fabricCanvas.remove(item);
  fabricCanvas.renderAll();
}

This may help you to accomplish your probs!!! I think so .

SakthiSureshAnand
  • 1,324
  • 16
  • 32