centeredRotation issue

by Andrea Bogazzi

HTML

<script src="https://rawgithub.com/kangax/fabric.js/master/dist/fabric.js"></script>
<body>
  <canvas id="c" width="500" height="300" style="border: 1px solid #00ffff;"></canvas>
</body>

CSS

canvas {
  border: 1px solid #999;
}

JavaScript

CANVAS = window._canvas = new fabric.Canvas('c');

let rect = new fabric.Rect({
    left: 100,
    top: 100,
    width: 200,
    height: 100, 
    originX: 'left',
    originY: 'top',
    fill: 'blue'
});
CANVAS.add(rect);

// Rotate 90 degrees when 'Alt' is pressed
window.addEventListener("keydown", eventListenerKeydown);
function eventListenerKeydown(evt) {
    if (evt.key == "Alt") {
        // Saving pre-rotation [x,y] to use in bugFix()
        
	      rect.rotate(rect.angle + 90);
        CANVAS.setupCurrentTransform();
        
        CANVAS.renderAll();
        evt.preventDefault();
		}
}

// Update the current transform used in dragging the object to account for the rotation