javascript - Undo/Redo for send forward & bring backward functionality in canvas with fabric.js -
i using fabric.js creating customized shoe design. wanted add undo & redo functionality & done fiddle link.
i used below code pushing canvas state.
function changelayer(direction) { var activeobject = canvas.getactiveobject(); if (activeobject) { if (direction == 'fore') console.log(canvas.bringforward(activeobject)); else console.log(canvas.sendbackwards(activeobject)); } pushstate(); } function pushstate() { if (replayflag === false) { // i.e. user modified something.. var itemprops = []; (var in selectedobject) { itemprops.push({ "itemnum": selectedobject[i].itemnum, "left": selectedobject[i].left, "top": selectedobject[i].top, "scalex": selectedobject[i].scalex, "scaley": selectedobject[i].scaley, "angle": selectedobject[i].angle, "flipx": selectedobject[i].flipx, "flipy": selectedobject[i].flipy, "fill": selectedobject[i].fill, "fontsize": selectedobject[i].fontsize, "fontfamily": selectedobject[i].fontfamily, "textbackgroundcolor": selectedobject[i].textbackgroundcolor, "fontweight": selectedobject[i].fontweight, "fontstyle": selectedobject[i].fontstyle, "textdecoration": selectedobject[i].textdecoration }); } // current object properties onobjectselected(); undohist.push({ "action": "modify", "itemprops": itemprops }); redohist = []; } } when bring element forward or backward, undo/redo functionality doesn't work properly.
Comments
Post a Comment