Fix selected shapes shifting to canvas origin (#2729)

* Fix selected shapes shifting to canvas origin

* Make only newly added shape selected even if it...

... overlaps with another
This commit is contained in:
Hikaru Y 2023-10-13 08:58:43 +09:00 committed by GitHub
parent 6c2205663e
commit 7cf19ea213
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 0 deletions

View File

@ -36,6 +36,10 @@ export function exportShapesToClozeDeletions(occludeInactive: boolean): {
*/
function baseShapesFromFabric(occludeInactive: boolean): ShapeOrShapes[] {
const canvas = globalThis.canvas as Canvas;
// Prevents multiple shapes in 'activeSelection' from shifting to the canvas origin
canvas.discardActiveObject();
makeMaskTransparent(canvas, false);
const objects = canvas.getObjects() as FabricObject[];
return objects

View File

@ -115,6 +115,7 @@ export const drawEllipse = (canvas: fabric.Canvas): void => {
}
ellipse.setCoords();
canvas.setActiveObject(ellipse);
undoStack.onObjectAdded(ellipse.id);
});
};

View File

@ -189,6 +189,7 @@ const generatePolygon = (canvas: fabric.Canvas, pointsList): void => {
if (polygon.width > 5 && polygon.height > 5) {
disableRotation(polygon);
canvas.add(polygon);
canvas.setActiveObject(polygon);
// view undo redo tools
undoStack.onObjectAdded(polygon.id);
emitChangeSignal();

View File

@ -109,6 +109,7 @@ export const drawRectangle = (canvas: fabric.Canvas): void => {
}
rect.setCoords();
canvas.setActiveObject(rect);
undoStack.onObjectAdded(rect.id);
});
};

View File

@ -38,6 +38,7 @@ export const drawText = (canvas: fabric.Canvas): void => {
disableRotation(text);
enableUniformScaling(canvas, text);
canvas.add(text);
canvas.setActiveObject(text);
undoStack.onObjectAdded(text.id);
});
};